当前位置: 首页>>代码示例>>C#>>正文


C# SqlCommand.AddParams方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:j-burrows,项目名称:repository,代码行数:11,代码来源:tCommandExtensions.cs

示例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);
     }
 }
开发者ID:j-burrows,项目名称:repository,代码行数:11,代码来源:tCommandExtensions.cs

示例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();
     }
 }
开发者ID:eugman,项目名称:Oak,代码行数:16,代码来源:Massive.cs

示例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()));
            }
        }
开发者ID:BillKeenan,项目名称:massive-mysql,代码行数:15,代码来源:Massive.MySql.cs

示例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;
         }
     }
 }
开发者ID:developmentalmadness,项目名称:massive,代码行数:24,代码来源:Massive.cs


注:本文中的System.Data.SqlClient.SqlCommand.AddParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。