请问,为什么使用OleDbCommand.ExecuteNonQuery()插入一条记录,插入成功后,返回值还是为0?
private static void PrepareCommand(OleDbCommand cmd,CommandType cmdType,string cmdText,OleDbParameter[] cmdParms){
cmd.CommandType = cmdType;
cmd.CommandText = cmdText;
if (cmdParms != null)
foreach (OleDbParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
public static int ExecuteNonQueryByTransaction(String connectionString, CommandType cmdType, string cmdText, params OleDbParameter[] commandParameters)
{
int val = 0;
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = conn.CreateCommand();
if (conn.State != ConnectionState.Open)
conn.Open();
OleDbTransaction trans = conn.BeginTransaction();
try
{
PrepareCommand(cmd, cmdType, cmdText, commandParameters);
cmd.Transaction = trans;
val = cmd.ExecuteNonQuery();
trans.Commit();
}
catch
{
trans.Rollback();
}
finally
{
cmd.Parameters.Clear();
conn.Close();
conn.Dispose();
trans.Dispose();
cmd.Dispose();
}
return val;
} --------------------编程问答-------------------- 调试看下返回的val 值为多少
并且在DB中查看下是否有该记录 --------------------编程问答-------------------- 调试查过了val的值为0 --------------------编程问答-------------------- 调试查过了val的值为0,但记录已插入成功 --------------------编程问答-------------------- 这个方法好像不返回操作记录的数量。,忘了代码了。晚上回家查了原来的代码告诉你
补充:.NET技术 , ASP.NET