.net的SQL语句问题
sqlsum="update[Goods]setSum="+sum+"whereGoodsName='"+a+"'";这句有语法错误了吗???怎么老提示我有update语...
sqlsum = "update [Goods] set Sum=" + sum + " where GoodsName='" + a + "'";这句有语法错误了吗???怎么老提示我有update语法错误??
下面是详细代码:
__________________________________________________________________
string strconn = "Provider = Microsoft.Jet.OleDb.4.0; Data Source=D:\\work\\采购系统\\App_Data\\采购系统.mdb";
OleDbConnection conn2 = new OleDbConnection(strconn);conn2.Open();
string sql1, sql2, sql3, sql4, sql5, sql6, sql7, sql8, sql9, sql10, sql11, sql12, sql13, sql14, sql15, sql16, sqlsum;for (int a = 1, sum = 0; a < 5; a++){sql1 = "select 电表1班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd1 = new OleDbCommand(sql1, conn2);int ret1 = (int)cmd1.ExecuteScalar();if (ret1 == 1) { ret1 = 0; }sql2 = "select 电表2班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd2 = new OleDbCommand(sql2, conn2);int ret2 = (int)cmd2.ExecuteScalar();if (ret2 == 1) { ret2 = 0; }sql3 = "select 电表3班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd3 = new OleDbCommand(sql3, conn2);int ret3 = (int)cmd3.ExecuteScalar();if (ret3 == 1) { ret3 = 0; }sql4 = "select 电表4班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd4 = new OleDbCommand(sql4, conn2);int ret4 = (int)cmd4.ExecuteScalar();if (ret4 == 1) { ret4 = 0; }sql5 = "select 电表5班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd5 = new OleDbCommand(sql5, conn2);int ret5 = (int)cmd5.ExecuteScalar();if (ret5 == 1) { ret5 = 0; }sql6 = "select 用户1班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd6 = new OleDbCommand(sql6, conn2);int ret6 = (int)cmd6.ExecuteScalar();if (ret6 == 1) { ret6 = 0; }sql7 = "select 用户2班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd7 = new OleDbCommand(sql7, conn2);int ret7 = (int)cmd7.ExecuteScalar();if (ret7 == 1) { ret7 = 0; }sql8 = "select 用户3班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd8 = new OleDbCommand(sql8, conn2);int ret8 = (int)cmd8.ExecuteScalar();if (ret8 == 1) { ret8 = 0; }sql9 = "select 用户4班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd9 = new OleDbCommand(sql9, conn2);int ret9 = (int)cmd9.ExecuteScalar();if (ret9 == 1) { ret9 = 0; }sql10 = "select 用户5班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd10 = new OleDbCommand(sql10, conn2);int ret10 = (int)cmd10.ExecuteScalar();if (ret10 == 1) { ret10 = 0; } sum = ret1 + ret2 + ret3 + ret4 + ret5 + ret6 + ret7 + ret8 + ret9 + ret10;
sqlsum = "update [Goods] set Sum=" + sum + " where GoodsName='" + a + "'";
OleDbCommand cmdsum = new OleDbCommand(sqlsum, conn2);
cmdsum.ExecuteNonQuery();
}
conn2.Close();
写错了~开头和详细里面都写错了
这句才对:
sqlsum = "update [Goods] set Sum=" + sum + " where GoodsID=" + a + "";
谁看看是什么原因老说我语法错误~~
张琎朋友~你说的问题我都检查过N多次啦~~都没你说的问题~~你看看嘛~~ 展开
下面是详细代码:
__________________________________________________________________
string strconn = "Provider = Microsoft.Jet.OleDb.4.0; Data Source=D:\\work\\采购系统\\App_Data\\采购系统.mdb";
OleDbConnection conn2 = new OleDbConnection(strconn);conn2.Open();
string sql1, sql2, sql3, sql4, sql5, sql6, sql7, sql8, sql9, sql10, sql11, sql12, sql13, sql14, sql15, sql16, sqlsum;for (int a = 1, sum = 0; a < 5; a++){sql1 = "select 电表1班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd1 = new OleDbCommand(sql1, conn2);int ret1 = (int)cmd1.ExecuteScalar();if (ret1 == 1) { ret1 = 0; }sql2 = "select 电表2班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd2 = new OleDbCommand(sql2, conn2);int ret2 = (int)cmd2.ExecuteScalar();if (ret2 == 1) { ret2 = 0; }sql3 = "select 电表3班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd3 = new OleDbCommand(sql3, conn2);int ret3 = (int)cmd3.ExecuteScalar();if (ret3 == 1) { ret3 = 0; }sql4 = "select 电表4班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd4 = new OleDbCommand(sql4, conn2);int ret4 = (int)cmd4.ExecuteScalar();if (ret4 == 1) { ret4 = 0; }sql5 = "select 电表5班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd5 = new OleDbCommand(sql5, conn2);int ret5 = (int)cmd5.ExecuteScalar();if (ret5 == 1) { ret5 = 0; }sql6 = "select 用户1班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd6 = new OleDbCommand(sql6, conn2);int ret6 = (int)cmd6.ExecuteScalar();if (ret6 == 1) { ret6 = 0; }sql7 = "select 用户2班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd7 = new OleDbCommand(sql7, conn2);int ret7 = (int)cmd7.ExecuteScalar();if (ret7 == 1) { ret7 = 0; }sql8 = "select 用户3班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd8 = new OleDbCommand(sql8, conn2);int ret8 = (int)cmd8.ExecuteScalar();if (ret8 == 1) { ret8 = 0; }sql9 = "select 用户4班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd9 = new OleDbCommand(sql9, conn2);int ret9 = (int)cmd9.ExecuteScalar();if (ret9 == 1) { ret9 = 0; }sql10 = "select 用户5班 from [Goods] where GoodsID=" + a + "";OleDbCommand cmd10 = new OleDbCommand(sql10, conn2);int ret10 = (int)cmd10.ExecuteScalar();if (ret10 == 1) { ret10 = 0; } sum = ret1 + ret2 + ret3 + ret4 + ret5 + ret6 + ret7 + ret8 + ret9 + ret10;
sqlsum = "update [Goods] set Sum=" + sum + " where GoodsName='" + a + "'";
OleDbCommand cmdsum = new OleDbCommand(sqlsum, conn2);
cmdsum.ExecuteNonQuery();
}
conn2.Close();
写错了~开头和详细里面都写错了
这句才对:
sqlsum = "update [Goods] set Sum=" + sum + " where GoodsID=" + a + "";
谁看看是什么原因老说我语法错误~~
张琎朋友~你说的问题我都检查过N多次啦~~都没你说的问题~~你看看嘛~~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询