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
0
1. Example
View licensepublic 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); }
0
2. Example
View licenseprivate DbCommand CreateCommandByCommandType(CommandType commandType, string commandText) { DbCommand command = dbProvider.DbProviderFactory.CreateCommand(); command.CommandType = commandType; command.CommandText = commandText; return command; }
0
3. Example
View licenseprivate DbCommand CreateCommandByCommandType(CommandType commandType, string commandText) { DbCommand command = dbProvider.DbProviderFactory.CreateCommand(); command.CommandType = commandType; command.CommandText = commandText; return command; }
0
4. Example
View licenseprivate DbCommand CreateCommandByCommandType(CommandType commandType, string commandText) { DbCommand command = dbProvider.DbProviderFactory.CreateCommand(); command.CommandType = commandType; command.CommandText = commandText; return command; }
0
5. Example
View licenseDbCommand CreateCommandByCommandType(CommandType commandType, string commandText) { DbCommand command = _DbProviderFactory.CreateCommand(); command.CommandType = commandType; command.CommandText = commandText; return command; }
0
6. Example
View licensepublic DbCommand CreateCommand() { return dbProviderFactory.CreateCommand(); }
0
7. Example
View licensepublic override DbCommand CreateCommand() { return new ProfiledDbCommand(tail.CreateCommand(), null, profiler); }
0
8. Example
View licensepublic IDbCommand CreateShowColumnsCommand(string tableName) { var command = DbProviderFactory.CreateCommand(); if (command != null) { command.CommandText = "show columns from " + tableName + ";"; } return command; }
0
9. Example
View licensepublic static DbCommand CreateCommand(this Database database) { return database.DbProviderFactory.CreateCommand(); }
0
10. Example
View licenseDbCommand 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; }
0
11. Example
View licensepublic override DbCommand CreateCommand() { var command = InnerFactory.CreateCommand(); if (IsAdoMonitoringNeeded()) { return new GlimpseDbCommand(command); } return command; }
0
12. Example
View licenseinternal 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; }
0
13. Example
View licenseDbCommand 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; }
0
14. Example
View licenseDbCommand 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; }
0
15. Example
View licensepublic 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; }
0
16. Example
View licenseinternal static DbCommand CreateCommand( string connectionStringName, DbConnection conn = null) { var factory = GetFactory(connectionStringName); var result = factory.CreateCommand(); result.Connection = conn; return result; }
0
17. Example
View licenseDbCommand 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; }
0
18. Example
View licensepublic 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; }
0
19. Example
View licenseDbCommand 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; }
0
20. Example
View licenseprivate 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; }
0
21. Example
View licenseinternal 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; }
0
22. Example
View licensepublic 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; }
0
23. Example
View licenseList<ForeignKey> LoadFKeys(string tblSchema, string tblName) { using (var /n ..... /n //View Source file for more details /n }
0
24. Example
View licensepublic 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(); }
0
25. Example
View licensepublic 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(); }
0
26. Example
View licensestring 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 ""; }
0
27. Example
View licensestring 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 ""; }
0
28. Example
View licenseIEnumerable<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(); } }
0
29. Example
View licenseprivate 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; }
0
30. Example
View licensepublic 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(); }
0
31. Example
View licenseprotected virtual DbCommand GetDbCommand() { var command = ProviderFactory.Creat/n ..... /n //View Source file for more details /n }
0
32. Example
View licenseList<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; } }
0
33. Example
View licensepublic void SqlSelectTable(string query, out ReportTable table) { DbCommand comm/n ..... /n //View Source file for more details /n }
0
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(); } } }
0
35. Example
View licenseList<TableIndex> LoadIndices(string tableName) { var result=new List<Ta/n ..... /n //View Source file for more details /n }
0
36. Example
View licensestring 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 ""; }
0
37. Example
View licensepublic 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; }
0
38. Example
View licenseList<Column> LoadColumns(Table tbl) { using (var cmd=this._factory.CreateC/n ..... /n //View Source file for more details /n }
0
39. Example
View licensestatic void Main(string[] args) { try { // Reads th/n ..... /n //View Source file for more details /n }
0
40. Example
View licenseList<Column> LoadColumns(Table tbl) { using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }
0
41. Example
View licenseList<ForeignKey> LoadForeignKeys(Table tbl) { using (var cmd = this._facto/n ..... /n //View Source file for more details /n }
0
42. Example
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(); } }
0
43. Example
View licenseList<Column> LoadColumns(Table tbl) { using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }
0
44. Example
View licensepublic override Tables ReadSchema(DbConnection connection, DbProviderFactory factory) { /n ..... /n //View Source file for more details /n }
0
45. Example
View licenseList<Column> LoadColumns(Table tbl) { using (var cmd = this._factory.Crea/n ..... /n //View Source file for more details /n }
0
46. Example
View license[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Jus/n ..... /n //View Source file for more details /n }
0
47. Example
View licensepublic override Tables ReadSchema(DbConnection connection, DbProviderFactory factory) { /n ..... /n //View Source file for more details /n }
0
48. Example
View licensepublic override Tables ReadSchema(DbConnection connection, DbProviderFactory factory) { /n ..... /n //View Source file for more details /n }
0
49. Example
View licenseList<TableIndex> LoadIndices(string schemaName, string tableName) { //var /n ..... /n //View Source file for more details /n }
0
50. Example
View licenseList<Column> LoadColumns(Table tbl) { using (var cmd=this._factory.Cr/n ..... /n //View Source file for more details /n }