大家好,又见面了,我是你们的朋友全栈君。
/// <summary> /// 执行参数查询 /// </summary> /// <param name=”cmd”>数据库执行命令</param> /// <param name=”conn”>数据库链接命令</param> /// <param name=”trans”>事务</param> /// <param name=”cmdText”>查询语句</param> /// <param name=”cmdParms”>查询参数</param> /// <returns></returns> 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; cmd.CommandType = CommandType.Text;//cmdType; if (cmdParms != null) { 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); } } }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155372.html原文链接:https://javaforall.cn