我有30个input的输入框!
名字分别是t1 t2 t3 t4 t5......t30
然后我写了一条循环
具体如下!product是产品表num是才产品表中得一个字段for(int i=1;i<=30;i++)
{
string sql="update product set num=num+" + Request["t"+ i] +" where id="+i+"";后面省略
}where已确认按钮之后就显示where附近有错误 也就是sql语句有错误!
正确的写法应该是什么?谢各路大侠!

解决方案 »

  1.   

    string sql="update product set num=num+" + Request["t"+ i] +" where id="+i+"";Response.Write(sql)
    看看sql是合法的
      

  2.   

    看看Request["t"+ i]是否有值有可能成为了set num = num + where id = ...
      

  3.   

    num 为字符串的情况
    for(int i=1;i<=30;i++)
    {
    string sql=string.Format("update product set num='num+{0}' where id={1}",Request["t"+ i],i);后面省略
    }num 为数值
    for(int i=1;i<=30;i++)
    {
    string sql=string.Format("update product set num=num+{0} where id={1}",ConvertToInt32(Request["t"+ i]),i);后面省略
    }
      

  4.   

    Response.Write(sql)输出看看就全明白了,估计没正确获取到值吧
    where 后面就只有id="+i?
      

  5.   

    确认你的30个input的输入框的name(HTML源码中)名字分别是t1 t2 t3 t4 t5......t30否则Request["t"+ i]将为null 导致拼接后的SQL语句变为set num=num + where