System.Data.Common.DbProviderFactory.CreateCommand()

Here are the examples of the csharp api class System.Data.Common.DbProviderFactory.CreateCommand() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

55 Examples 7

1. Example

View license
public override DbCommand CreateCommand()
        {
            var command = _dbProviderFactory.CreateCommand();
            if (command == null)
            {
                return null;
            }

            var profiledCommand = command as ProfiledDbCommand;
            if (profiledCommand != null)
            {
                return profiledCommand;
            }

            return new ProfiledDbCommand(command, _dbProfiler);
        }

2. Example

Project: Dos.ORM
Source File: Database.cs
View license
private DbCommand CreateCommandByCommandType(CommandType commandType, string commandText)
        {
            DbCommand command = dbProvider.DbProviderFactory.CreateCommand();
            command.CommandType = commandType;
            command.CommandText = commandText;
            
            return command;
        }

3. Example

Project: Dos.ORM
Source File: Database.cs
View license
private DbCommand CreateCommandByCommandType(CommandType commandType, string commandText)
        {
            DbCommand command = dbProvider.DbProviderFactory.CreateCommand();
            command.CommandType = commandType;
            command.CommandText = commandText;

            return command;
        }

4. Example

Project: Dos.ORM
Source File: Database.cs
View license
private DbCommand CreateCommandByCommandType(CommandType commandType, string commandText)
        {
            DbCommand command = dbProvider.DbProviderFactory.CreateCommand();
            command.CommandType = commandType;
            command.CommandText = commandText;

            return command;
        }

5. Example

Project: Kalman.Studio
Source File: Database.cs
View license
DbCommand CreateCommandByCommandType(CommandType commandType, string commandText)
        {
            DbCommand command = _DbProviderFactory.CreateCommand();
            command.CommandType = commandType;
            command.CommandText = commandText;

            return command;
        }

6. Example

View license
public DbCommand CreateCommand()
		{
			return dbProviderFactory.CreateCommand();
		}

7. Example

View license
public override DbCommand CreateCommand()
        {
            return new ProfiledDbCommand(tail.CreateCommand(), null, profiler);
        }

8. Example

Project: CommunityServer
Source File: DbFactory.cs
View license
public IDbCommand CreateShowColumnsCommand(string tableName)
        {
            var command = DbProviderFactory.CreateCommand();
            if (command != null)
            {
                command.CommandText = "show columns from " + tableName + ";";
            }
            return command;
        }

9. Example

View license
public static DbCommand CreateCommand(this Database database)
        {
            return database.DbProviderFactory.CreateCommand();
        }

10. Example

Project: RawDataAccessBencher
Source File: Massive.cs
View license
DbCommand CreateCommand(string sql, DbConnection conn, params object[] args)
		{
			var result = _factory.CreateCommand();
			result.Connection = conn;
			result.CommandText = sql;
			if(args.Length > 0)
				result.AddParams(args);
			return result;
		}

11. Example

Project: Glimpse
Source File: GlimpseDbProviderFactory.cs
View license
public override DbCommand CreateCommand()
        {
            var command = InnerFactory.CreateCommand();
            if (IsAdoMonitoringNeeded()) 
            {
                return new GlimpseDbCommand(command);
            }
            return command;
        }

12. Example

Project: DReAM
Source File: DataFactory.cs
View license
internal IDbCommand CreateProcedure(string name) {
            IDbCommand result;
            if(_factory != null) {
                result = _factory.CreateCommand();
                result.CommandText = name;
            } else {
                result = (IDbCommand)_commandConstructor.Invoke(new object[] { name });
            }
            result.CommandType = CommandType.StoredProcedure;
            return result;
        }

13. Example

Project: ReliableDbProvider
Source File: Massive.cs
View license
DbCommand CreateCommand(string sql, DbConnection conn, params object[] args)
        {
            var result = _factory.CreateCommand();
            result.Connection = conn;
            result.CommandText = sql;
            if (args.Length > 0)
                result.AddParams(args);
            return result;
        }

14. Example

Project: NServiceKit.OrmLite
Source File: Massive.cs
View license
DbCommand CreateCommand(string sql, DbConnection conn, params object[] args)
        {
            var result = _factory.CreateCommand();
            result.Connection = conn;
            result.CommandText = sql;
            if (args.Length > 0)
                result.AddParams(args);
            return result;
        }

15. Example

Project: CommunityServer
Source File: DbFactory.cs
View license
public IDbCommand CreateLastInsertIdCommand()
        {
            var command = DbProviderFactory.CreateCommand();
            if (command != null)
                command.CommandText =
                    ConnectionStringSettings.ProviderName.IndexOf("MySql", StringComparison.OrdinalIgnoreCase) != -1
                        ? "select Last_Insert_Id();"
                        : "select last_insert_rowid();";
            return command;
        }

16. Example

Project: Ilaro.Admin
Source File: DB.cs
View license
internal static DbCommand CreateCommand(
            string connectionStringName, 
            DbConnection conn = null)
        {
            var factory = GetFactory(connectionStringName);
            var result = factory.CreateCommand();
            result.Connection = conn;
            return result;
        }

17. Example

Project: Ilaro.Admin
Source File: Massive.cs
View license
DbCommand CreateCommand(string sql, DbConnection conn, params object[] args)
        {
            var result = _factory.CreateCommand();
            result.Connection = conn;
            result.CommandText = sql;
            if (args.Length > 0)
                result.AddParams(args);
            return result;
        }

18. Example

Project: OrigoDB
Source File: SqlCommandStore.cs
View license
public virtual DbCommand CreateAppendCommand()
        {
            var dbCommand = _providerFactory.CreateCommand();
            dbCommand.CommandText = _statements.AppendEntry;
            
            var param = _providerFactory.CreateParameter();
            param.ParameterName = "@Id";
            param.DbType = DbType.Int64;
            dbCommand.Parameters.Add(param);

            param = _providerFactory.CreateParameter();
            param.ParameterName = "@Created";
            param.DbType = DbType.DateTime;
            dbCommand.Parameters.Add(param);

            param = _providerFactory.CreateParameter();
            param.ParameterName = "@Type";
            param.DbType = DbType.String;
            param.Size = 1024;
            dbCommand.Parameters.Add(param);

            param = _providerFactory.CreateParameter();
            param.ParameterName = "@Data";
            param.DbType = DbType.Binary;
            dbCommand.Parameters.Add(param);


            return dbCommand;
        }

19. Example

Project: RawDataAccessBencher
Source File: Massive.cs
View license
DbCommand CreateCommand(string sql, DbConnection conn, params object[] args)
        {
            var newArgs = ToParams(args);
            var result = _factory.CreateCommand();
            result.Connection = conn;
            result.CommandText = sql;
            if (args.Length > 0)
                result.AddParams(newArgs);
            return result;
        }

20. Example

Project: LCLFramework
Source File: LIDbAccesser.cs
View license
private DbCommand CreateDbCommand(string sql, IList<DbParameter> parameters, CommandType commandType)
        {
            DbConnection connection = providerFactory.CreateConnection();
            DbCommand command = providerFactory.CreateCommand();
            connection.ConnectionString = ConnectionString;
            command.CommandText = sql;
            command.CommandType = commandType;
            command.Connection = connection;
            if (!(parameters == null || parameters.Count == 0))
            {
                foreach (DbParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }
            }
            return command;
        }

21. Example

Project: DReAM
Source File: DataFactory.cs
View license
internal IDbCommand CreateQuery(string query) {
            IDbCommand result = null;
            try {
                if (_factory != null) {
                    result = _factory.CreateCommand();
                    result.CommandText = query;
                } else {
                    result = (IDbCommand) _commandConstructor.Invoke(new object[] {query});
                }
            }catch {
                if(result != null) {

                    // must dispose of command in case of failure
                    result.Dispose();
                }
				throw;
            }
            return result;
        }

22. Example

Project: Destrier
Source File: Execute.cs
View license
public static System.Data.Common.DbCommand Command(String connectionString, DbProviderFactory providerFactory = null, int? commandTimeout = null)
        {
            commandTimeout = commandTimeout ?? COMMAND_TIMEOUT;

            connectionString = connectionString ?? DatabaseConfigurationContext.DefaultConnectionString;
            providerFactory = providerFactory ?? DatabaseConfigurationContext.DefaultProviderFactory;

            var connection = providerFactory.CreateConnection();
            connection.ConnectionString = connectionString;
            connection.Open();
            var cmd = providerFactory.CreateCommand();
            cmd.Connection = connection;
            cmd.Disposed += new EventHandler(cmd_Disposed);
            return cmd;
        }

23. Example

View license
List<ForeignKey> LoadFKeys(string tblSchema, string tblName)
        {
            using (var /n ..... /n //View Source file for more details /n }

24. Example

Project: ActivityManager
Source File: SqlDataSource.cs
View license
public void SqlSelectScalar(string query, out object result)
        {
            DbCommand command = factory.CreateCommand();
            command.CommandText = query;
            command.Connection = connection;
            if (transaction != null)
                command.Transaction = transaction;
            if (connection.State == ConnectionState.Closed)
            {
                if (permanent_connection)
                    throw new SqlException("?????????? ? ????? ?????? ???????? ?? ??????????? ????????");
                else
                    connection.Open();
            }
            result = command.ExecuteScalar();
            if (!permanent_connection)
                connection.Close();
        }

25. Example

Project: YAFNET
Source File: DbAccessBase.cs
View license
public virtual IDbCommand GetCommand(
            [NotNull] string sql, CommandType commandType = CommandType.StoredProcedure, [CanBeNull] IEnumerable<KeyValuePair<string, object>> parameters = null)
        {
            DbCommand cmd = this.DbProviderFactory.CreateCommand();
            parameters = parameters.IfNullEmpty();

            cmd.CommandTimeout = int.Parse(Config.SqlCommandTimeout);
            cmd.CommandType = commandType;

            cmd.CommandText = commandType == CommandType.StoredProcedure ? this.FormatProcedureText(sql) : sql;

            // map parameters for this command...
            this.MapParameters(cmd, parameters);

            return cmd.ReplaceCommandText();
        }

26. Example

View license
string GetPK(string table){
        
            string sql=@"SELECT kcu.column_name 
            FROM information_schema.key_column_usage kcu
            JOIN information_schema.table_constraints tc
            ON kcu.constraint_name=tc.constraint_name
            WHERE lower(tc.constraint_type)='primary key'
            AND kcu.table_name=@tablename";

            using (var cmd=this._factory.CreateCommand())
            {
                cmd.Connection=this._connection;
                cmd.CommandText=sql;

                var p = cmd.CreateParameter();
                p.ParameterName = "@tableName";
                p.Value=table;
                cmd.Parameters.Add(p);

                var result=cmd.ExecuteScalar();

                if(result!=null)
                    return result.ToString();    
            }	         
        
            return "";
        }

27. Example

View license
string GetPK(string table){
        
            string sql=@"SELECT KCU.COLUMN_NAME 
            FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU
            JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
            ON KCU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME
            WHERE TC.CONSTRAINT_TYPE='PRIMARY KEY'
            AND KCU.TABLE_NAME=@tableName";

            using (var cmd=this._factory.CreateCommand())
            {
                cmd.Connection=this._connection;
                cmd.CommandText=sql;

                var p = cmd.CreateParameter();
                p.ParameterName = "@tableName";
                p.Value=table;
                cmd.Parameters.Add(p);

                var result=cmd.ExecuteScalar();

                if(result!=null)
                    return result.ToString();    
            }	         
        
            return "";
        }

28. Example

View license
IEnumerable<string> GetPrimaryKey(string table)
        {
            using (var cmd = this._factory.CreateCommand())
            {
                cmd.Connection = this._connection;
                cmd.CommandText = PrimaryKeySql;

                var p = cmd.CreateParameter();
                p.ParameterName = "@tableName";
                p.Value = table;
                cmd.Parameters.Add(p);

                return cmd.Select(c => (string)c["ColumnName"]).ToList();
            }
        }

29. Example

Project: Glimpse
Source File: HomeController.cs
View license
private int GetAllAlbums()
        {  
            var rowcount = 0; 
            var ds = new DataSet();

            var connectionString = ConfigurationManager.ConnectionStrings["MusicStoreEntities"];
            var factory = DbProviderFactories.GetFactory(connectionString.ProviderName);  //factory: {Glimpse.Ado.AlternateType.GlimpseDbProviderFactory<System.Data.SqlClient.SqlClientFactory>}

            using (DbCommand cmd = factory.CreateCommand()) //cmd: {Glimpse.Ado.AlternateType.GlimpseDbCommand} 
            { 
                //cmd.CommandType = CommandType.StoredProcedure; 
                cmd.CommandText = "SELECT * FROM Albums";

                using (DbConnection con = factory.CreateConnection()) //con: {Glimpse.Ado.AlternateType.GlimpseDbConnection} 
                {
                    con.ConnectionString = connectionString.ConnectionString; 
                    cmd.Connection = con;

                    IDbDataAdapter dbAdapter = factory.CreateDataAdapter(); //dbAdapter: {System.Data.SqlClient.SqlDataAdapter} not GlimpseDbDataAdapter 
                    dbAdapter.SelectCommand = cmd;

                    dbAdapter.Fill(ds); 
                } 
            }

            rowcount = ds.Tables[0].Rows.Count;

            return rowcount; 
        }

30. Example

Project: ActivityManager
Source File: SqlDataSource.cs
View license
public void SqlModifyQuery(string query, out int rowsAffected)
        {
            DbCommand command = factory.CreateCommand();
            command.CommandText = query;
            command.Connection = connection;
            if (transaction != null)
                command.Transaction = transaction;
            if (connection.State == ConnectionState.Closed)
            {
                if (permanent_connection)
                    throw new SqlException("?????????? ???????? ?? ??????????? ????????");
                else
                    connection.Open();
            }
            try
            {
                rowsAffected = command.ExecuteNonQuery();
            }
            catch (InvalidOperationException e)
            {
                SqlRollbackTransaction();
                throw new InvalidOperationException(e.Message);
            }
            if (!permanent_connection)
                connection.Close();
        }

31. Example

View license
protected virtual DbCommand GetDbCommand()
        {
            var command = ProviderFactory.Creat/n ..... /n //View Source file for more details /n }

32. Example

View license
List<ForeignKey> LoadForeignKeys(string tblName)
        {
            using (var cmd=this._factory.CreateCommand())
            {
                cmd.Connection=this._connection;
                cmd.CommandText=String.Format(FKEY_INFO_SQL,tblName);

                var result=new List<ForeignKey>();
                using (IDataReader rdr=cmd.ExecuteReader())
                {
                    while(rdr.Read())
                    {
                        ForeignKey key=new ForeignKey();
                        key.PrimaryTable=rdr["table"].ToString();
                        key.PrimaryColumns=new [] { rdr["to"].ToString() };
                        key.ForeignColumns=new [] { rdr["from"].ToString() };
                        result.Add(key);
                    }
                }
                return result;
            }
        }

33. Example

Project: ActivityManager
Source File: SqlDataSource.cs
View license
public void SqlSelectTable(string query, out ReportTable table)
        {
            DbCommand comm/n ..... /n //View Source file for more details /n }

34. Example

View license
[Fact]
    public void ClientFactory()
    {
      DbProviderFactory f = new MySqlClientFactory();
      using (DbConnection c = f.CreateConnection())
      {
        DbConnectionStringBuilder cb = f.CreateConnectionStringBuilder();
        cb.ConnectionString = st.GetConnectionString(true);
        c.ConnectionString = cb.ConnectionString;
        c.Open();

        DbCommand cmd = f.CreateCommand();
        cmd.Connection = c;
        cmd.CommandText = "SELECT 1";
        cmd.CommandType = CommandType.Text;
        using (DbDataReader reader = cmd.ExecuteReader())
        {
          reader.Read();
        }
      }
    }

35. Example

View license
List<TableIndex> LoadIndices(string tableName)
        {
            var result=new List<Ta/n ..... /n //View Source file for more details /n }

36. Example

View license
string GetPK(string table){
        
            string sql=@"select column_name from USER_CONSTRAINTS uc
  inner join USER_CONS_COLUMNS ucc on uc.constraint_name = ucc.constraint_name
where uc.constraint_type = 'P'
and uc.table_name = upper(:tableName)
and ucc.position = 1";

            using (var cmd=this._factory.CreateCommand())
            {
                cmd.Connection=this._connection;
                cmd.CommandText=sql;
                cmd.GetType().GetProperty("BindByName").SetValue(cmd, true, null);

                var p = cmd.CreateParameter();
                p.ParameterName = ":tableName";
                p.Value=table;
                cmd.Parameters.Add(p);

                var result=cmd.ExecuteScalar();

                if(result!=null)
                    return result.ToString();    
            }	         
        
            return "";
        }

37. Example

View license
public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
        {
            var result=new Tables();	
            this._connection=connection;
            this._factory=factory;
            var cmd=this._factory.CreateCommand();        
            cmd.Connection=connection;
            cmd.CommandText=TABLE_SQL;
            //cmd.GetType().GetProperty("BindByName").SetValue(cmd, true, null);
            //pull the tables in a reader
            using(cmd)
            {
                using (var rdr=cmd.ExecuteReader())
                {
                    while(rdr.Read())
                    {
                        Table tbl=new Table();
                        tbl.Name=rdr["name"].ToString();
                        tbl.Schema = "";
                        tbl.IsView=String.Compare(rdr["type"].ToString(), "view", true)==0;
                        tbl.CleanName=CleanUp(tbl.Name);
                        tbl.ClassName=Inflector.MakeSingular(tbl.CleanName);
                        tbl.SQL = rdr["sql"].ToString();
                        result.Add(tbl);
                    }
                }
            }
            foreach (var tbl in result)
            {
                tbl.Columns=this.LoadColumns(tbl);
                tbl.Indexes = this.LoadIndices(tbl.Name);
                tbl.ForeignKeys = this.LoadForeignKeys(tbl.Name);
            }
            return result;
        }

38. Example

View license
List<Column> LoadColumns(Table tbl)
        {
            using (var cmd=this._factory.CreateC/n ..... /n //View Source file for more details /n }

39. Example

Project: NosDB
Source File: Program.cs
View license
static void Main(string[] args)
        {
            try
            {

                // Reads th/n ..... /n //View Source file for more details /n }

40. Example

View license
List<Column> LoadColumns(Table tbl)
        {
    
            using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }

41. Example

View license
List<ForeignKey> LoadForeignKeys(Table tbl)
        {
            using (var cmd = this._facto/n ..... /n //View Source file for more details /n }

42. Example

Project: nuodb-dotnet
Source File: TestFixture.cs
View license
[Test]
        public void TestDbProvider()
        {
            DbProviderFactory factory = new NuoDbProviderFactory();
            using (DbConnection cn = factory.CreateConnection())
            {
                DbConnectionStringBuilder conStrBuilder = factory.CreateConnectionStringBuilder();
                conStrBuilder["Server"] = host;
                conStrBuilder["User"] = user;
                conStrBuilder["Password"] = password;
                conStrBuilder["Schema"] = schema;
                conStrBuilder["Database"] = database;
                Console.WriteLine("Connection string = {0}", conStrBuilder.ConnectionString);

                cn.ConnectionString = conStrBuilder.ConnectionString;
                cn.Open();

                DbCommand cmd = factory.CreateCommand();
                cmd.Connection = cn;
                cmd.CommandText = "select * from hockey";

                DbDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", reader[0], reader[1], reader[2], reader["id"]);
                }
                reader.Close();
            }
        }

43. Example

View license
List<Column> LoadColumns(Table tbl)
        {
    
            using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }

44. Example

View license
public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
        {
    /n ..... /n //View Source file for more details /n }

45. Example

View license
List<Column> LoadColumns(Table tbl)
        {

            using (var cmd = this._factory.Crea/n ..... /n //View Source file for more details /n }

46. Example

Project: MIMWAL
Source File: ExpressionFunction.cs
View license
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Jus/n ..... /n //View Source file for more details /n }

47. Example

Project: fluentmigrator
Source File: MySqlSchemaReader.cs
View license
public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
        {
    /n ..... /n //View Source file for more details /n }

48. Example

View license
public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
        {
    /n ..... /n //View Source file for more details /n }

49. Example

View license
List<TableIndex> LoadIndices(string schemaName, string tableName)
        {
            //var /n ..... /n //View Source file for more details /n }

50. Example

View license
List<Column> LoadColumns(Table tbl)
        {
    
            using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }