从数据库中取出数据 填充到资料填写文本框 用户修改和填写其他选项后提交 存储过程

 

protected void GetUserInfo()
 {
     if (Session["UserID"] != null)
     {
         ViewState["CID"] = myShare.GetAObject(true, 1, "CustomerID", "Customers", "UserID='" + Session["UserID"].ToString() + "'").ToString();
         SqlConnection con = null;
         con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
         string sql = "select C.FullName,C.Cellula,C.EmailAddress,C.egoFax1,C.ZipCode,C.Address,V.VendorName,V.HomePage,V.Introduce from Customers C left join Vendors V on C..CustomerID=V.CustomerID where C.CustomerID= '" + ViewState["CID"].ToString() + "'";
         SqlCommand com = new SqlCommand(sql, con);
         con.Open();
         SqlDataReader sdr = com.ExecuteReader();
         while (sdr.Read())
         {
             this.txtCompay.Text = sdr["VendorName"].ToString();
             this.txtName.Text = sdr["FullName"].ToString();
             this.txtTel.Text = sdr["Cellula"].ToString();
             this.txtEmail.Text = sdr["EmailAddress"].ToString();
             this.txtFax.Text = sdr["egoFax1"].ToString();
             this.txtWebsite.Text = sdr["HomePage"].ToString();
             this.txtPostcode.Text = sdr["ZipCode"].ToString();
             this.txtAddress.Text = sdr["Address"].ToString();
             this.txtContent.Text = sdr["Introduce"].ToString();
         }
         con.Close();
     }
 }
 
 protected void btnSend_Click(object sender, EventArgs e)
 {
     int temp = -1;
     int exhibitionID = int.Parse(Request.QueryString["ConList"]);
 
     int mCustomerID = Convert.ToInt32(ViewState["CID"].ToString());
     string company = this.txtCompay.Text.Trim();
     string name = this.txtName.Text;
     string tel = this.txtTel.Text;
     string email = this.txtEmail.Text;
     string fax = this.txtFax.Text;
     string website = this.txtWebsite.Text;
     string zipcode = this.txtPostcode.Text;
     string address = this.txtAddress.Text;
     string companyintroduce = this.txtContent.Text;
     string require = this.txtRequire.Text;
 
     SqlConnection con = null;
     try
     {
         con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
         SqlCommand com = new SqlCommand();
         com.Connection = con;
         com.CommandType = CommandType.StoredProcedure;
         com.CommandText = "conventionApply";
         con.Open();
         SqlParameter[] sp = 
         {
             new SqlParameter("@CustomerID",SqlDbType.Int)
             ,new SqlParameter("@CompanyName",SqlDbType.NVarChar,100)
             ,new SqlParameter("@Contact",SqlDbType.VarChar,50)
             ,new SqlParameter("@Email",SqlDbType.VarChar,50)
             ,new SqlParameter("@Tel",SqlDbType.VarChar,20)
             ,new SqlParameter("@Fax",SqlDbType.VarChar,20)
             ,new SqlParameter("@Zipcode",SqlDbType.VarChar,10)
             ,new SqlParameter("@Url",SqlDbType.NVarChar,100)
             ,new SqlParameter("@Address",SqlDbType.NVarChar,200)
             ,new SqlParameter("@CompanyIntroduce",SqlDbType.NVarChar,300)
             ,new SqlParameter("@Requirements",SqlDbType.NVarChar,300)
             ,new SqlParameter("@ExhibitionID",SqlDbType.Int)
             ,new SqlParameter("@ReturnValue",SqlDbType.Int)
 
          };
         sp[0].Value = mCustomerID;
         sp[1].Value = company;
         sp[2].Value = name;
         sp[3].Value = email;
         sp[4].Value = tel;
         sp[5].Value = fax;
         sp[6].Value = zipcode;
         sp[7].Value = website;
         sp[8].Value = address;
         sp[9].Value = companyintroduce;
         sp[10].Value = require;
         sp[11].Value = exhibitionID;
         sp[12].Direction = ParameterDirection.Output;
         com.Parameters.AddRange(sp);
         com.ExecuteNonQuery();
         temp = Convert.ToInt32(com.Parameters["@ReturnValue"].Value);
         con.Close();
     }
     catch (SqlException se)
     {
     }
     finally
     {
         con.Close();
     }
 
     if (temp == -1)
     {
         myShare.WebMessageBox(this.Page, "信息发布时出错,请重试!");
     }
     else if (temp == 0)
     {
         myShare.WebMessageBox(this.Page, "信息发布失败,请重试!");
     }
     else
     {
         ClientScript.RegisterStartupScript(ClientScript.GetType(), "提示", "<script>alert('信息发布成功!');window.location='ConventionList.aspx'</script>");
     }
 }
 
 

存储过程:

create proc conventionApply
@CustomerID int,
@CompanyName NVarChar(100),
@Contact VarChar(50),
@Email VarChar(50),
@Tel VarChar(20),
@Fax VarChar(20),
@Zipcode VarChar(10),
@Url NVarChar(100),
@Address NVarChar(200),
@CompanyIntroduce NVarChar(300),
@Requirements NVarChar(300),
@ReturnValue Int output
WITH ENCRYPTION AS
begin    
    set @ReturnValue=0
 
    DECLARE @EC_TempID int    
    BEGIN    
         insert into Exhibitors(CustomerID,CompanyName,Contact,Email,Tel,Fax,Zipcode,Url,Address,CompanyIntroduce,Requirements) 
         values(@CustomerID,@CompanyName,@Contact,@Email,@Tel,@Fax,@Zipcode,@Url,@Address,@CompanyIntroduce,@Requirements) 
    
         SELECT @EC_TempID=SCOPE_IDENTITY()
         IF @EC_TempID=0
            BEGIN
                SET @ReturnValue=-1
            END
        else
            begin
                set @ReturnValue=@EC_TempID
            end
    END 
end 

你可能感兴趣的:(存储过程)