本文整理汇总了C#中System.Data.SqlClient.SqlCommand.PopulateParameters方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.PopulateParameters方法的具体用法?C# SqlCommand.PopulateParameters怎么用?C# SqlCommand.PopulateParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.PopulateParameters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScalar
/// <summary>
/// Executes the SQL statement using <see cref="SqlConnection"/>, and returns the value in the first column
/// of the first row in the resultset.
/// </summary>
/// <param name="sql">The SQL statement to be executed.</param>
/// <param name="connection">The <see cref="SqlConnection"/> to use for executing the SQL statement.</param>
/// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
/// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
/// <returns>Value in the first column of the first row in the resultset.</returns>
public static object ExecuteScalar(this SqlConnection connection, string sql, int timeout, params object[] parameters)
{
SqlCommand command = new SqlCommand(sql, connection);
command.CommandTimeout = timeout;
command.PopulateParameters(parameters);
return command.ExecuteScalar();
}
示例2: RetrieveDataSet
/// <summary>
/// Executes the SQL statement using <see cref="SqlConnection"/>, and returns the <see cref="DataSet"/> that
/// may contain multiple tables, depending on the SQL statement.
/// </summary>
/// <param name="sql">The SQL statement to be executed.</param>
/// <param name="connection">The <see cref="SqlConnection"/> to use for executing the SQL statement.</param>
/// <param name="startRow">The zero-based record number to start with.</param>
/// <param name="maxRows">The maximum number of records to retrieve.</param>
/// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
/// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
/// <returns>A <see cref="DataSet"/> object.</returns>
public static DataSet RetrieveDataSet(this SqlConnection connection, string sql, int startRow, int maxRows, int timeout, params object[] parameters)
{
SqlCommand command = new SqlCommand(sql, connection);
command.CommandTimeout = timeout;
command.PopulateParameters(parameters);
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
DataSet data = new DataSet("Temp");
dataAdapter.Fill(data, startRow, maxRows, "Table1");
return data;
}
示例3: ExecuteReader
/// <summary>
/// Executes the SQL statement using <see cref="SqlConnection"/>, and builds a <see cref="SqlDataReader"/>.
/// </summary>
/// <param name="sql">The SQL statement to be executed.</param>
/// <param name="connection">The <see cref="SqlConnection"/> to use for executing the SQL statement.</param>
/// <param name="behavior">One of the <see cref="CommandBehavior"/> values.</param>
/// <param name="timeout">The time in seconds to wait for the SQL statement to execute.</param>
/// <param name="parameters">The parameters to be passed to the SQL stored procedure being executed.</param>
/// <returns>A <see cref="SqlDataReader"/> object.</returns>
public static SqlDataReader ExecuteReader(this SqlConnection connection, string sql, CommandBehavior behavior, int timeout, params object[] parameters)
{
SqlCommand command = new SqlCommand(sql, connection);
command.CommandTimeout = timeout;
command.PopulateParameters(parameters);
return command.ExecuteReader(behavior);
}