各位大哥大姐 :
我问一下我的DataSet1中的表是表1现在要把这个相加后的值放到表2中去 下面是代码      不知道为什么一运行到这就错
string wqe="select sum  (数量) as  '"+ TB7.Text.Trim()+"'  from 表2 where 代号='"+TB4.Text +"' group by 数量";
string select="update 表 set 数量='"+wqe+"' where 代号='"+TB4.Text +"'";
string aaa="server=172.20.20.128;database=111;uid=sa;pwd=";
SqlConnection Conn=new SqlConnection(aaa);
SqlCommand mycommand2=new SqlCommand(wqe,Conn);
Conn.Open();
mycommand2.ExecuteNonQuery (); //到这就错 第 1 行: '=' 附近有语法错误。
Conn.Close();

解决方案 »

  1.   

    不行还是错 去掉'"+wqe+"'的单引号  第 1 行: '=' 附近有语法错误。在关键字 'where' 附近有语法错误。 
    去掉 '"+ TB7.Text.Trim()+"'的单引号  第 1 行: '=' 附近有语法错误。 
    都去掉就是第 1 行: '=' 附近有语法错误。第 1 行: '输入的数量' 附近有语法错误。
    我怀疑上面的代码没有把数据放到表2中去
      

  2.   

    ="select sum  (数量) as  '"+ TB7.Text.Trim()+"'  from 表2 where 代号='"+TB4.Text +"' group by 数量";
    -------------------------------------------------------------------------------------
    这句有问题吗??改成下面这样:
    ="select sum(数量)='"+ TB7.Text.Trim()+"'  from 表2 where 代号='"+ TB4.Text +"'";
      

  3.   

    上面有点问题:这样
    ="select sum(数量) as '"+ TB7.Text.Trim()+"'  from 表2 where 代号='"+ TB4.Text +"'";
      

  4.   

    修改为:string wqe="select sum (数量) as " + TB7.Text.Trim() + " from 表2 where 代号 = '" + TB4.Text + "' group by 代号";
    string select="update 表 set 数量 = (" + wqe + ") where 代号 = '"+TB4.Text +"'";
    string aaa="server=172.20.20.128;database=111;uid=sa;pwd=";
    SqlConnection Conn=new SqlConnection(aaa);
    SqlCommand mycommand2=new SqlCommand(wqe,Conn);
    Conn.Open();
    mycommand2.ExecuteNonQuery (); //到这就错 第 1 行: '=' 附近有语法错误。
    Conn.Close();
      

  5.   

    1)查询的表不对吧,应该是从表1查吧
    2)string aaa="server=172.20.20.128;database=111;uid=sa;pwd=";//pwd后面应该有分号吧
      

  6.   

    那就把: TB7.Text.Trim()改成TB7.text
      

  7.   

    既然是SUM数量,怎么能GROUP BY数量呢?注意整理一下单引号,好几个地方单引号错误
      

  8.   

    你贴了伪代码上来,我们也很难查找问题,你自己跟踪一下你的SQL语句不就很简单了?
      

  9.   

    伪代码??   我这个代码是用来更新数据库中已有的物品的数量的 怎么是伪代码啦 
    我用SQL查询分析器  来查它都说=旁边有错误啊