日期:2014-05-18 浏览次数:20935 次
string runner = dt.Rows[0]["name"].ToString(); string message = "123"; SqlParameter[] pars={ new SqlParameter("@runner",runner), new SqlParameter("@message",message) }; common.common.executeNoQuery("addLog", true, pars);
/// <summary> /// 执行无返回值的sql语句或存储过程 /// </summary> /// <param name="cmdText">要执行的sql语句或存储过程</param> /// <param name="IsStroed">true:存储过程,false:sql语句</param> /// <param name="parameters">执行时所需要的参数</param> public static void executeNoQuery(string cmdText,bool IsStroed,params SqlParameter[] parameters) { sqlHelp.sqlHelp.executeNoQuery(cmdText, IsStroed, parameters); }
/// <summary> /// 执行无返回值的sql语句或存储过程 /// </summary> /// <param name="cmdText">要执行的sql语句或存储过程</param> /// <param name="IsStroed">true:存储过程,false:sql语句</param> /// <param name="parameters">执行时所需要的参数</param> public static void executeNoQuery(string cmdText,bool IsStroed,params SqlParameter[] parameters) { using (SqlConnection conn = getConn()) { if (conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken) { conn.Open(); } SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = cmdText; if (IsStroed == true) { cmd.CommandType = CommandType.StoredProcedure; } cmd.Parameters.Clear(); foreach (SqlParameter par in parameters) { cmd.Parameters.Add(par); } int i= cmd.ExecuteNonQuery(); cmd.Dispose(); } }