ExecuteReader(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
以params 声明的参数是说明参数的个数是可选的,可以为0个或多个。当多个时,以“,”分开传入
一个参数:
ExecuteReader(System.Data.CommandType.Text,"select * from table1 where id =@id",new System.Data.SqlClient.SqlParameter("@id",12));
多个参数:
ExecuteReader(System.Data.CommandType.Text,"select * from table1 where id =@id and name=@name", new System.Data.SqlClient.SqlParameter("@id",12),new System.Data.SqlClient.SqlParameter("@name","中国"));
可以这样调用
public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { //... } SqlParameter a = SqlParameter a = new SqlParameter("@name", "中国"); SqlParameter b = SqlParameter a = new SqlParameter("@name", "中国"); SqlParameter c = SqlParameter a = new SqlParameter("@name", "中国"); SqlParameter d = SqlParameter a = new SqlParameter("@name", "中国"); ExecuteNonQuery(conn, cmdType, cmdText, a, b, c, d);
因为是params 声明的,所以这个参数你可以不填。或传入一个事先设置好的SqlParameter类型的数组。
发表评论
-
like参数查询
2011-05-24 14:45 810//在做项目的时候遇到使用like参数查询 public ... -
母版页的嵌套
2011-05-24 14:41 3492在嵌套母版页时遇到的问题 在嵌套母版页的时候,最 ... -
删除指定路径的文件
2011-05-04 17:59 861string path = this.Server.Map ... -
获取表单的值
2011-04-18 16:22 673//获取单个表单的值 Request.Form[&quo ... -
C# 正则 获取 Img Src路径
2011-04-15 14:15 5202string str = "<form ... -
C#记录Cookie
2011-04-08 13:44 1104//以一维的形式记录Cookie Response.Co ... -
取机器名, CPU号 硬盘号 网卡号 串口
2011-04-07 21:41 1118//取机器名 public string G ... -
Asp.net获取用户真实Ip地址
2011-04-01 10:39 10125/// <summary> ... -
数据库连接字符串
2011-03-29 21:19 657<connectionStrings> ... -
一般处理程序(ashx)使用Session
2011-03-28 17:18 1273using System; using System.C ... -
实现退出功能
2011-03-21 10:49 1004<a href="login.aspx?a ... -
后台添加Css或Js文件
2011-03-15 15:57 711protected void Page_Load(obje ... -
验证码的比较
2011-03-14 18:24 887[align=left] /// <summary&g ... -
利用ListItem[]给DropDownList绑定数据
2011-03-14 17:41 2844protected void Page_Load(ob ... -
C#生成GUID代码
2011-02-13 19:57 977Response.Write(System.Guid.Ne ... -
ASP.NET会话(Session)保存模式
2011-02-01 20:43 1779ASP.NET会话(Session)保 ... -
Asp.net相对路径与绝对路径
2011-01-28 22:15 1433[size=medium] 1.Request.Applic ... -
判断数据库表中字段是否为空
2011-01-26 22:46 1400[size=medium] string strSql = ... -
类型转换集合
2011-01-25 23:30 752将空字符串转换为Null值 string str = & ... -
C# 各种字符串格式
2011-01-25 22:45 841[size=medium] 1. C#的Strin ...
相关推荐
public static int ExecteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand cmd = new SqlCommand(); using (SqlConnection ...
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, trans...
public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters) { SqlCommand command = connection.CreateCommand(); ...
public SqlDataReader ExecuteReader(string sql, params SqlParameter[] parameters) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(sql...
public static int ExecuteCommand(string sql, params SqlParameter[] values) { SqlCommand cmd = new SqlCommand(sql, Connection); cmd.Parameters.AddRange(values); return cmd.ExecuteNonQuery(); } ...
/// <param name="commandParameters">SqlParameter[]参数数组 /// <returns>SqlDataReader:执行结果的记录集 public SqlDataReader GetSqlReader(CommandType cmdType, string cmdText, params SqlParameter[] ...
public async Task<int> ExecuteNonQueryAsync(string commandText, params SqlParameter[] parameters) { await _connection.OpenAsync(); using var command = new SqlCommand(commandText, _connection); ...
public SqlDataReader ExecuteDataReader(string procName, SqlParameter[] params) { SqlCommand command = new SqlCommand(procName, conn); command.CommandType = CommandType.StoredProcedure; if ...
public static void ExecuteNonQuery(string connectionString, string sql, params SqlParameter[] parameters) { using (SqlConnection connection = new SqlConnection(connectionString)) { connection....
CommandType commandType, string commandText, params SqlParameter[] commandParameters) Execute* (SqlConnection connection, string spName, params object[] parameterValues) 除这些重载以外,除 ...
private static void PreCommand(SqlConnection conn, SqlCommand cmd, string sql, params SqlParameter[] Parms) { //打开数据库 if (conn.State == ConnectionState.Closed) { conn.Open(); } cmd....
public override SqlDataReader GetSqlDataReader(string sql, params SqlParameter[] commandParameters) { SqlConnection connection = GetSqlConnection(); SqlCommand command = new SqlCommand(sql, ...
public DataTable ExecuteDataTable(string sql, params SqlParameter[] parameters) { DataTable dt = new DataTable(); using (SqlConnection conn = OpenConnection()) { using (SqlCommand cmd = new ...
public static int ExecuteNonQuery(string connectionString, string sql, params SqlParameter[] parameters) { using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new ...
public int ExecuteNonQuery(SqlConnection connection, string sql, params SqlParameter[] parameters) { SqlCommand command = new SqlCommand(sql, connection); command.Parameters.AddRange(parameters); ...
CommandType commandType, string commandText, params SqlParameter[] commandParameters) Execute* (SqlConnection connection, string spName, params object[] parameterValues) 除这些重载以外,除 ...
public static int ExecuteCommand(params SqlParameter[] values) { SqlCommand cmd = new SqlCommand(); cmd.Connection = Connection; cmd.CommandText = "Pro_UpdateBooksCategory"; cmd.CommandType = ...
public DataTable Select(string sql, params SqlParameter[] parameters) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(sql, ...
public static bool Exists(string strSql, params SqlParameter[] cmdParms) { object obj = GetSingle(strSql, cmdParms); int cmdresult; if ((Object.Equals(obj, null)) || (Object.Equals(obj, System....
在SQL查询中,`params`通常用于预编译的语句中,如PreparedStatement,以防止SQL注入攻击。 10. **参数对象(Parameter Objects)** 有时候,一组相关的参数可以被封装到一个对象中,形成参数对象,这有助于提高...