日期:2014-05-17 浏览次数:20699 次
public static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter cmdParms) { if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) { cmd.Transaction = trans; } cmd.CommandType = CommandType.Text; if (cmdParms != null) { foreach (OleDbParameter parm in cmdParms) { cmd.Parameters.Add(parm); } } }
/// <summary> /// 构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上) /// </summary> /// <param name="cmd">执行对象</param> /// <param name="conn">连接对象</param> /// <param name="trans">事务对象</param> /// <param name="cmdText">SQL命令</param> /// <param name="cmdParms">执行命令的参数</param> public static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter cmdParms) { if (conn.State != ConnectionState.Open) { //如果没打数据库连接则打开数据库连接 conn.Open(); } //将cmd的Connection设置为con cmd.Connection = conn; //将cmd的CommandText设置为cmdText cmd.CommandText = cmdText; if (trans != null) { //将事务trans设置到cmd上 cmd.Transaction = trans; } //执行的SQL文本,不是存储过程 cmd.CommandType = CommandType.Text; if (cmdParms != null) { //将cmdParms参数绑定到cmd上 foreach (OleDbParameter parm in cmdParms) { cmd.Parameters.Add(parm); } } }
------解决方案--------------------
将参数加进Command对象
用到了事务
------解决方案--------------------
构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上)
------解决方案--------------------