本文整理汇总了C#中System.Data.SqlClient.SqlCommand.AddParams方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.AddParams方法的具体用法?C# SqlCommand.AddParams怎么用?C# SqlCommand.AddParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.AddParams方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandWhenAdd_N_Params_IncreasesSizeByN
public void CommandWhenAdd_N_Params_IncreasesSizeByN()
{
using(SqlCommand command = new SqlCommand()){
command.AddParams(
new Param("Name1", "Value1"),
new Param("Name2", "Value2"),
new Param("Name3", "Value3")
);
Assert.AreEqual(3, command.Parameters.Count);
}
}
示例2: CommandWhenAdd_N_Params_HasMatchingValues
public void CommandWhenAdd_N_Params_HasMatchingValues()
{
using(SqlCommand command = new SqlCommand()){
command.AddParams(
new Param("Name1", "Value1"),
new Param("Name2", "Value2"),
new Param("Name3", "Value3")
);
Assert.AreEqual("Value2", command.Parameters[1].Value);
}
}
示例3: QueryAsync
/// <summary>
/// Executes the reader using SQL async API - thanks to Damian Edwards
/// </summary>
public void QueryAsync(string sql, Action<List<dynamic>> callback, params object[] args)
{
using (var conn = new SqlConnection(ConnectionProfile.ConnectionString))
{
var cmd = new SqlCommand(sql, new SqlConnection(ConnectionProfile.ConnectionString));
cmd.AddParams(args);
cmd.Connection.Open();
var task = Task.Factory.FromAsync<IDataReader>(cmd.BeginExecuteReader, cmd.EndExecuteReader, null);
task.ContinueWith(x => callback.Invoke(x.Result.ToGeminiList(Projection)));
//make sure this is closed off.
conn.Close();
}
}
示例4: QueryAsync
/// <summary>
/// Executes the reader using SQL async API - thanks to Damian Edwards
/// </summary>
public void QueryAsync(string sql, Action<List<dynamic>> callback, params object[] args)
{
using (var conn = new SqlConnection(_connectionString))
{
var cmd = new SqlCommand(sql, conn);
cmd.AddParams(args);
conn.Open();
var task = Task.Factory.FromAsync<IDataReader>(cmd.BeginExecuteReader, cmd.EndExecuteReader, null);
task.ContinueWith(x => callback.Invoke(x.Result.ToExpandoList()));
}
}
示例5: QueryAsync
/// <summary>
/// Executes the reader using SQL async API - thanks to Damian Edwards
/// </summary>
public void QueryAsync(string sql, Action<List<dynamic>> callback, params object[] args)
{
var conn = new SqlConnection(ConnectionString);
using(var cmd = new SqlCommand(sql, conn)){
cmd.AddParams(args);
try{
conn.Open();
var task = Task.Factory.FromAsync<IDataReader>(cmd.BeginExecuteReader, cmd.EndExecuteReader, null);
task.ContinueWith(x => {
var result = x.Result.ToExpandoList();
conn.Dispose();
callback.Invoke(result);
});
}
catch (DbException){
if (conn.State == ConnectionState.Open)
conn.Close();
throw;
}
}
}