问题描述
privatestaticvoidPrepareCommand(OleDbCommandcmd,CommandTypecmdType,stringcmdText,OleDbParameter[]cmdParms){cmd.CommandType=cmdType;cmd.CommandText=cmdText;if(cmdParms!=null)foreach(OleDbParameterparmincmdParms)cmd.Parameters.Add(parm);}publicstaticintExecuteNonQueryByTransaction(StringconnectionString,CommandTypecmdType,stringcmdText,paramsOleDbParameter[]commandParameters){intval=0;OleDbConnectionconn=newOleDbConnection(connectionString);OleDbCommandcmd=conn.CreateCommand();if(conn.State!=ConnectionState.Open)conn.Open();OleDbTransactiontrans=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();}returnval;}
解决方案
解决方案二:
调试看下返回的val值为多少并且在DB中查看下是否有该记录
解决方案三:
调试查过了val的值为0
解决方案四:
调试查过了val的值为0,但记录已插入成功
解决方案五:
这个方法好像不返回操作记录的数量。,忘了代码了。晚上回家查了原来的代码告诉你