日期:2014-05-18  浏览次数:20394 次

100分求解 与数据库中的值相加 解决就散分
这是添加按钮中的问题   我想在按钮中更新2个表。   一个是表1,一个是表。
在表1中插入数据已经实现。但在表中更新数据老是提示错误。下面是代码
private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
if(TB2.Text   != " ")  
{
string   aaa= "server=172.20.20.128;database=111;uid=sa;pwd= ";
SqlConnection   Conn=new   SqlConnection(aaa);
string   strCommand= "select   count(*)   from   表1   where   序号   like   ' "+TB2.Text   + " ' ";  
//查看序号是不是已经存在    
SqlCommand   mycommand=new   SqlCommand(strCommand,Conn);
Conn.Open();
int   flag=(int)   mycommand.ExecuteScalar();
Conn.Close();
if(flag==0)  
{  
string   strCon= "select   count(*)   from   表   where   代号   like   ' "+TB4.Text   + " ' ";  
//查看代号是不是已经存在    
SqlCommand   mycommand1=new   SqlCommand(strCon,Conn);
Conn.Open();
int   flg=(int)   mycommand1.ExecuteScalar();
Conn.Close();
if(flg==0)
{
string   select= "insert   into   表(序号,代号,图样编号,名称,数量,备注) ";  
select+= "   values( ' "+TB2.Text+ " ', ' "+TB4.Text+ " ', ' "+TB5.Text   + " ', ' "+   TB6.Text+ " ', ' "+   TB7.Text+ " ', ' "+   TB10.Text+ " ') ";  
SqlCommand   mycommand2=new   SqlCommand(select,Conn);
Conn.Open();
mycommand2.ExecuteNonQuery   ();  
Conn.Close();
}
else
{
string   wqe= "select   sum   (数量)   as   "+   TB7.Text.Trim()+ "   from   表   where   代号= ' "+TB4.Text   + " ' ";  
string   select= "update   表   set   备注= ' "+TB10.Text   + " ',数量=( "+wqe+ ")   where   代号= ' "+TB4.Text   + " ' ";   //就是这边发生错误   把上一句和,数量=( "+wqe+ ")   删除也说是有错误     这个更新又不是Datagird   总不会要DataKeys[e.Item.ItemIndex]这个吧??
SqlCommand   mycommand2=new   SqlCommand(select,Conn);  
Conn.Open();
mycommand2.ExecuteNonQuery   ();  
Conn.Close();
}
string   selectstr= "insert   into   表1(ID,序号,出库编号,代号,图样编号,名称,数量,领出人,备注,登记人) ";  
selectstr+= "   values( ' "+TB1.Text+ " ', ' "+TB2.Text+ " ', ' "+TB3.Text+ " ', ' "+TB4.Text+ " ', ' "+TB5.Text   + " ', ' "+   TB6.Text+ " ', ' "+   TB7.Text+ " ', ' "+   TB9.Text+ " ', ' "+TB10.Text+ " ', ' "+   TB11.Text+ " ') ";  
SqlCommand   addcommand=new   SqlCommand(selectstr,Conn);
Conn.Open();
addcommand.ExecuteNonQuery   ();  
Conn.Close();
//清空TB中的数据
TB1.Text= " ";  
TB2.Text= " ";  
TB3.Text= " ";  
TB4.Text= " ";  
TB5.Text= " ";
TB6.Text= " ";
TB7.Text= " ";
TB9.Text= " ";
TB10.Text= " ";
TB11.Text= " ";
Response.Redirect( "yjck.aspx ");
}  
else  
{ &