日期:2014-05-18 浏览次数:20453 次
/// <summary> /// 执行SQL语句,返回影响的记录数 /// </summary> /// <param name="SQLString">SQL语句</param> /// <returns>影响的记录数</returns> public static int ExecuteSql(string SQLString, params SqlParameter[] cmdParms) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { try { PrepareCommand(cmd, connection, null, SQLString, cmdParms); int rows = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return rows; } catch (System.Data.SqlClient.SqlException e) { throw e; } } } }
IDataParameter[] p = new IDataParameter[3]; p[0] = new SqlParameter("@a",SqlDbType.NVarChar,50); p[1] = new SqlParameter("@b", SqlDbType.Text); p[2] = new SqlParameter("@c",SqlDbType.Text); string sql = "insert into report (user_name,content,url)values(@a,@b,@c)"; return DbHelperSQL.ExecuteSql(sql, p);