现在又一列列名,分别为zb1,zb2...zb107.想给每一列存进dropdownlist里的value值。zb后边的变量1-107想用一个循环的变量来控制 
for (int i = 1; i <= 107; i++) 
            { 
                ContentPlaceHolder cph = this.Form.FindControl("ContentPlaceHolder2") as ContentPlaceHolder; 
                DropDownList ddl = cph.FindControl("DropDownList" + i) as DropDownList;                 if (ddl != null) 
                { 
                    int a = int.Parse(ddl.SelectedValue); 
                    int b = Convert.ToInt32(TextBox1.Text); 
                    SqlConnection con = new SqlConnection("Server=.;database=QINXINJITUAN;uid=sa;pwd=179425532;"); 
                    try 
                    { 
                        con.Open(); 
                        string str = "update ZHtjqrx set zb='" + a+ "'where year='" + b + "'"; 
                        SqlCommand cmd = new SqlCommand(string.Format(str), con); 
                        cmd.ExecuteNonQuery(); 
                    } 
                    catch (Exception ex) 
                    { 
                        Response.Write(ex.Message); 
                    } 
                    finally 
                    {                         con.Close(); 
                    } 
                }             } 
关键行为红色的那一行,请问zb那一块怎么写?

解决方案 »

  1.   

    上边是INT,下边就成了单引号的string了~~
      

  2.   

    <a href="http://www.gongzuo99.com">http://www.gongzuo99.com</a>  可以
      

  3.   


    " + a+ " where year=" + b + "
      

  4.   

    string str = string.Format("update ZHtjqrx set zb={0} where year='{1}'",a,b); 
      

  5.   

    上下类型不匹配
    上面是int
    下面是string  你的sql语句
      

  6.   

    我还没有试您的代码,不过我觉得我是想做一个1-107的一个循环,您这样能实现么?而且我意思是说zb后边是跟着一个变量的,比如说zba,后边这个a是一个从1-107的一个循环变量,来控制不同的列名zb1到zb107.这些不一样的列名放在set后面,应该怎么写。也就是说这个zba应该提前处理一下。关键是这个处理代码怎么写
      

  7.   

    string str = string.Format("update ZHtjqrx set zb{0}={1} where year='{2}'",i,a,b);
    多加一个参数就好啦