日期:2014-05-19  浏览次数:21568 次

cmd.ExecuteNonQuery();调试时该语句出错,求救~~~~
代码如下:Global.cnn.Open();
SqlCommand   cmd   =   Global.cnn.CreateCommand();
cmd.CommandText   =   "UPDATE   tblEquipment   SET   "   +
"EquipmentID   =   @EquipmentID,   "   +
                  "EquipmentName   =   @EquipmentName,   "   +
"EquipmentDescription   =   @EquipmentDescription,   "   +
"WHERE   EquipmentKey   =   "   +   keyRecord;
cmd.Parameters.Add(new   SqlParameter  
                  ( "@EquipmentID ",SqlDbType.VarChar,8));
cmd.Parameters[ "@EquipmentID "].Value   =   tbxEquipmentID.Text;
cmd.Parameters.Add(new   SqlParameter             ( "@EquipmentName ",SqlDbType.VarChar,50));
cmd.Parameters[ "@EquipmentName "].Value   =   tbxEquipmentName.Text;
cmd.Parameters.Add(new   SqlParameter       ( "@EquipmentDescription ",SqlDbType.VarChar,50));
cmd.Parameters[ "@EquipmentDescription "].Value   =   tbxEquipmentDescription.Text;
cmd.ExecuteNonQuery();
Global.cnn.Close();
drv.EndEdit();
dsEquipment.AcceptChanges();
调试时cmd.ExecuteNonQuery();语句出错,运行时出错提示:      
    未处理的“System.Data.OleDb.OleDbException”类型的异常出现在       system.data.dll       中。


------解决方案--------------------
cmd.CommandText = "UPDATE tblEquipment SET " +
"EquipmentID = @EquipmentID, " +
"EquipmentName = @EquipmentName, " +
"EquipmentDescription = @EquipmentDescription, " +
"WHERE EquipmentKey = " + keyRecord;


改为:
cmd.CommandText = "UPDATE tblEquipment SET " +
"EquipmentID = @EquipmentID, " +
"EquipmentName = @EquipmentName, " +
"EquipmentDescription = @EquipmentDescription " + // 多了一个逗号
"WHERE EquipmentKey = " + keyRecord;

相关资料更多>