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


C# this.CreateCommand方法代码示例

本文整理汇总了C#中this.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# this.CreateCommand方法的具体用法?C# this.CreateCommand怎么用?C# this.CreateCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TableExists

 public static bool TableExists(this IDbConnection connection,string tableName)
 {
     bool exists;
     try
     {
         connection.Open();
         // ANSI SQL
         var cmd = connection.CreateCommand();
         cmd.CommandText = string.Format("select case when exists((select * from information_schema.tables " +
                                         "where table_name = '{0}')) then 1 else 0 end", tableName);
         exists = (int) cmd.ExecuteScalar() == 1;
     }
     catch
     {
         try
         {
             // Other RDBMS.
             exists = true;
             var cmd = connection.CreateCommand();
             cmd.CommandText = string.Format("select 1 from {0} where 1 = 0", tableName);
             cmd.ExecuteNonQuery();
         }
         catch
         {
             exists = false;
         }
     }
     finally
     {
         connection.Close();
     }
     return exists;
 }
开发者ID:wjch-krl,项目名称:Affrodite,代码行数:33,代码来源:Extensions.cs

示例2: CreateCommand

        public static IDbCommand CreateCommand(this IDbConnection connection, AdoOptions options)
        {
            if (options == null || options.CommandTimeout < 0) return connection.CreateCommand();

            var command = connection.CreateCommand();
            command.CommandTimeout = options.CommandTimeout;
            return command;
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:8,代码来源:DbConnectionEx.cs

示例3: ExecuteReader

 public static SqlDataReader ExecuteReader(this SqlConnection connection, string commandText)
 {
     using (SqlCommand command = connection.CreateCommand(commandText))
     {
         return command.ExecuteReader();
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:7,代码来源:SqlConnectionHelper.cs

示例4: ExecuteNonQuery

 public static int ExecuteNonQuery(this SqlConnection connection, string commandText)
 {
     using (SqlCommand command = connection.CreateCommand(commandText))
     {
         return command.ExecuteNonQuery();
     }
 }
开发者ID:tomtung,项目名称:Homework.PatentApplicationSystem,代码行数:7,代码来源:SqlConnectionHelper.cs

示例5: GetColumns

        /// <summary>
        /// Gets the names of all tables in the current database
        /// </summary>
        public static Dictionary<string, SqlDbType> GetColumns(this SqlConnection connection, string tableName, SqlTransaction transaction = null)
        {
            var results = new Dictionary<string, SqlDbType>();

            using (var command = connection.CreateCommand())
            {
                if (transaction != null)
                {
                    command.Transaction = transaction;
                }

                command.CommandText = $"SELECT [COLUMN_NAME] AS 'name', [DATA_TYPE] AS 'type' FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '{tableName}'";

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var name = (string)reader["name"];
                        var typeString = (string)reader["type"];
                        var type = GetDbType(typeString);

                        results[name] = type;
                    }
                }
            }

            return results;
        }
开发者ID:RichieYang,项目名称:Rebus,代码行数:31,代码来源:SqlServerMagic.cs

示例6: TableExists

 public static bool TableExists(this SqliteConnection connection, string name)
 {
     using (var reader = connection.CreateCommand($"PRAGMA table_info(\"{name}\")").ExecuteReader())
     {
         return reader.Read();
     }
 }
开发者ID:rgripper,项目名称:SillyGeo,代码行数:7,代码来源:SqliteExtensions.cs

示例7: ExecuteUpdateQuery

 public static int ExecuteUpdateQuery(this IDbConnection connection, string sql, Action<IDbCommand> prepare)
 {
   var command = connection.CreateCommand();
   command.CommandText = sql;
   prepare(command);
   return command.ExecuteNonQuery();
 }
开发者ID:machine,项目名称:machine.sqlmap,代码行数:7,代码来源:AdoNetHelpers.cs

示例8: GetCommand

        static DbCommand GetCommand(this DbConnection connection, string toExecute)
        {
            DbCommand command = connection.CreateCommand();
            command.CommandText = toExecute;

            return command;
        }
开发者ID:SystemDot,项目名称:SystemDotServiceBus,代码行数:7,代码来源:DbConnectionExtensions.cs

示例9: CreateCommand

        public static IDbCommand CreateCommand(this IDbProvider dbProvider, string sql, CommandType cmdType = CommandType.Text, Func<IDbCommand, IDbDataParameter[]> getParas = null)
        {
            var conn = dbProvider.CreateConnection();
            if (conn.State != ConnectionState.Open)
                conn.Open();
            var trans = conn.BeginTransaction();
            var cmd = dbProvider.CreateCommand(conn);

            IDbDataParameter[] paras = null;
            if (getParas != null)
                paras = getParas(cmd);

            dbProvider.PrepareCommand(ref cmdType, ref sql, ref paras);
            cmd.CommandType = cmdType;
            cmd.CommandText = sql;

            if (paras != null && paras.Length > 0)
            {
                foreach (var p in paras)
                {
                    dbProvider.AttachParameter(cmd, p);
                }
            }
            cmd.Transaction = trans;
            return cmd;
        }
开发者ID:cairabbit,项目名称:daf,代码行数:26,代码来源:IDbProvider.cs

示例10: CreateCommand

        /// <summary>
        /// An overload of CreateCommand that accepts a command text
        /// </summary>
        /// <param name="factory">The connection for which the command is created</param>
        /// <param name="query">The command text for the command</param>
        /// <returns>A command for the connection with command text set</returns>
        public static DbCommand CreateCommand(this DbConnection connection, string query)
        {
            var command = connection.CreateCommand();
            command.CommandText = query;

            return command;
        }
开发者ID:MichaelAz,项目名称:TINA-ORM,代码行数:13,代码来源:Extensions.cs

示例11: CreateCommand

 public static SqlCommand CreateCommand(this SqlConnection connection, string commandText, CommandType commandType)
 {
     var command = connection.CreateCommand();
     command.CommandText = commandText;
     command.CommandType = commandType;
     return command;
 }
开发者ID:zeldafreak,项目名称:Area51,代码行数:7,代码来源:SqlConnectionExtensions.cs

示例12: CreateCommand

 public static DbCommand CreateCommand(this DbProviderFactory factory,
     Action<DbCommand> setup)
 {
     DbCommand command = factory.CreateCommand();
     setup(command);
     return command;
 }
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:7,代码来源:DbFactoryExtensions.cs

示例13: GetPoisonMessage

 /// <summary>
 /// Gets a single Poison Message, including message body and exception details.
 /// </summary>
 public static PoisonMessageInfo GetPoisonMessage(this SqlConnection connection, Guid conversation_handle)
 {
     using (var cmd = connection.CreateCommand())
     {
         var param = cmd.CreateParameter();
         param.ParameterName = "@conversation_handle";
         param.Value = conversation_handle;
         param.DbType = DbType.Guid;
         cmd.Parameters.Add(param);
         cmd.CommandText = Query_PosionMessage;
         using (var reader = cmd.ExecuteReader())
         {
             while (reader.Read())
             {
                 var message = new PoisonMessageInfo()
                 {
                     ConversationHandle = reader.GetGuid(0),
                     InsertDateTimeUTC = reader.GetDateTime(1),
                     QueueName = reader.GetString(2),
                     ServiceName = reader.GetString(3),
                     OriginServiceName = reader.GetString(4),
                     Retries = reader.GetInt32(5),
                     ErrorCode = reader.GetString(6),
                     ErrorMessage = reader.GetString(7),
                     MessageBody = reader.GetSqlBytes(8).Buffer,
                 };
                 return message;
             }
             return null;
         }
     }
 }
开发者ID:jdaigle,项目名称:LightRail,代码行数:35,代码来源:ServiceBrokerWatcher.cs

示例14: CreateSqlStringCommand

        /// <summary>
        /// 创建一个执行Sql语句的DbCommand
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DbCommand CreateSqlStringCommand(this DbProviderFactory dbFactory, string sql)
        {
            DbCommand retValue = dbFactory.CreateCommand();
            retValue.CommandText = sql;

            return retValue;
        }
开发者ID:JackFong,项目名称:QuantumCode.LRTree,代码行数:12,代码来源:DBProviderFactoryExtensions.cs

示例15: CreateCommand

        public static NpgsqlCommand CreateCommand(this NpgsqlConnection conn, string command)
        {
            var cmd = conn.CreateCommand();
            cmd.CommandText = command;

            return cmd;
        }
开发者ID:bojanv91,项目名称:Marten,代码行数:7,代码来源:CommandExtensions.cs


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