标签:style blog color io 数据 for cti ar
/// <summary> /// 执行参数查询 /// </summary> /// <param name="cmd">数据库执行命令</param> /// <param name="conn">数据库连接命令</param> /// <param name="trans">事务</param> /// <param name="cmdText">查询语句</param> /// <param name="cmdParms">查询参数</param> private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, string cmdText, SqlParameter[] cmdParms) { if (conn.State != ConnectionState.Open) conn.Open(); cmd.Connection = conn; cmd.CommandText = cmdText; if (trans != null) cmd.Transaction = trans; //指定SqlCommand类的事务 cmd.CommandType = CommandType.Text;//指定sqlcommand类的CommandText属性的解释类型 if (cmdParms != null)//如果插入的参数不为空,则foreach循环遍历加入到SqlCommand类的参数属性中 { foreach (SqlParameter parameter in cmdParms) { if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) && (parameter.Value == null)) { parameter.Value = DBNull.Value; } cmd.Parameters.Add(parameter); } }
标签:style blog color io 数据 for cti ar
原文地址:http://www.cnblogs.com/Vennet/p/3890326.html