insert into数据库里面没有数据,请帮忙看看。
protected void Button2_Click(object sender, EventArgs e)
    {        for (int i = 0; i < this.GridView1.Rows.Count; i++)
           
        {
         
            string value1 = (this.GridView1.Rows[i].FindControl("TextBox1") as TextBox).Text.Trim(); 
            string value2 = (this.GridView1.Rows[i].FindControl("TextBox2") as TextBox).Text.Trim();
            string value3 = (this.GridView1.Rows[i].FindControl("TextBox3") as TextBox).Text.Trim();
            string value4 = (this.GridView1.Rows[i].FindControl("TextBox4") as TextBox).Text.Trim();            RadioButton rb = GridView1.Rows[i].FindControl("RadioButton1") as RadioButton;
            if (rb.Checked)
            {
                string str2 = "是";
            }
            else
            {
                string str2 = "否";
            }
            DropDownList ddl = GridView1.Rows[i].FindControl("DropDownList1") as DropDownList;
            if (ddl.SelectedValue != "")
            {                string str2 = ddl.SelectedValue;
            }             SqlConnection conn = zong.createcon();
            conn.Open();
            string sql = "insert into qqyy values xm='" + value1 + "',gh='" + value2 + "',jz='" + value3 + "',lb='" + value4 + "','"+rb+"','"+ddl+"'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
      
        }

解决方案 »

  1.   

    string sql = "insert into qqyy(xm,gh,jz,lb) values('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "'");
      

  2.   

    rb 和ddl
    是控件
    要是加的话要if (rb.Checked)
      {
      string rbstr = "是";
      }
      else
      {
      string rbstr = "否";
      }
      DropDownList ddl = GridView1.Rows[i].FindControl("DropDownList1") as DropDownList;
      if (ddl.SelectedValue != "")
      {  string ddlstr= ddl.SelectedValue;
      }
    rb换成rbstr  
    ddl换成ddlstr
      

  3.   

    如果这里是Lable的话,这句代码怎么写?
    string value1 = (this.GridView1.Rows[i].FindControl("TextBox1") as TextBox).Text.Trim();  
      

  4.   

    string value1 = (this.GridView1.Rows[i].FindControl("Label1") as Label).Text.Trim();
      

  5.   

    在gridview中,xm,gh,jz,la是数据绑定的。
    我现在需要把上面的几个插入到另外的表中。
    那string value1 = (this.GridView1.Rows[i].FindControl("Label1") as Label).Text.Trim();
    这样是不是正确的?
      

  6.   

    在gridview中,xm,gh,jz,la是数据绑定的。
    我现在需要把上面的几个插入到另外的表中。
    那string value1 = (this.GridView1.Rows[i].FindControl("Label1") as Label).Text.Trim();
    这样是不是正确的?
      

  7.   

    在gridview中,xm,gh,jz,la是数据绑定的。
    我现在需要把上面的几个插入到另外的表中。
    那string value1 = (this.GridView1.Rows[i].FindControl("Label1") as Label).Text.Trim();
    我转成了模板,这样是不是正确的?