static public void Main() { string myConnectionString = "Host=myserver.mycompany.com;" + "User Id=myname;PWD=mypass;" + "Database=mydatabase"; using (DbConnection conn = new IngresConnection()) { conn.ConnectionString = myConnectionString; conn.Open(); // open the Ingres connection string cmdtext = "select table_owner, table_name, " + " create_date from iitables " + " where table_type in ('T','V') and " + " table_name not like 'ii%' and" + " table_name not like 'II%'"; DbCommand cmd = conn.CreateCommand(); cmd.CommandText = cmdtext; DataSet ds = new DataSet("my_list_of_tables"); // read the data using the DataAdapter method DbDataAdapter adapter = new IngresDataAdapter(); adapter.SelectCommand = cmd; adapter.Fill(ds); // execute the query and fill the dataset // write the dataset to an XML file ds.WriteXml("c:/temp/temp.xml"); } // close the connection } // end Main()
static void Main(string[] args) { string SQLStatement = "select * from revenue"; // SQLStatement = "delete from revenue"; // SQLStatement = "insert into revenue(myid, material, revenue) values(1, 'Flower', 12.34)"; // SQLStatement = "insert into revenue(myid, material, revenue) values(2, 'car', 1.34)"; // SQLStatement = "insert into revenue(myid, material, revenue) values(3, '花', 26.989)"; // SQLStatement = "insert into revenue(myid, material, revenue) values(3, '汽车',26.989)"; IngresConnection con = new IngresConnection(string.Format("Host={0};Database={1};Uid={2};Pwd={3}", "XXX", "demodb", "Administrator", "HX")); IngresDataAdapter da = new IngresDataAdapter(new IngresCommand(SQLStatement, con)); DataTable sqlresult = new DataTable(); da.Fill(sqlresult); con.Close(); da.Dispose(); foreach (DataColumn sqlcol in sqlresult.Columns) { Console.WriteLine(sqlcol.DataType); } Console.WriteLine(sqlresult.Rows.Count); Console.Read(); }
//public DataAdapterWizard() : this(new IngresDataAdapter(), null) //{ //} public DataAdapterWizard( IngresDataAdapter adapter, System.ComponentModel.Design.IDesignerHost host) { Form dlgWelcome = new DataAdapterWizardWelcomeForm(); DataAdapterWizardGenerateForm dlgGenerate = null; DialogResult result = DialogResult.OK; //goto debugLabel; ShowWelcome: result = dlgWelcome.ShowDialog(); if (result == DialogResult.Cancel) // if Cancel button, return { return; } //debugLabel: ConnectionEditor connectionEditor = new ConnectionEditor(adapter, host); if (dlgGenerate == null) { dlgGenerate = new DataAdapterWizardGenerateForm(adapter.SelectCommand); } //ShowGenerate: result = dlgGenerate.ShowDialog(); if (result == DialogResult.Cancel) // if Cancel button, return { return; } // update the SelectCommand with the entry from the form's text if (result == DialogResult.Retry) // if Back button, go back one { goto ShowWelcome; } adapter.SelectCommand.CommandText = dlgGenerate.CommandText; try { TableMappings.Generate(adapter); } catch (Exception ex) { MessageBox.Show( "Could not generate DataAdapter's TableMappings.\n" + ex.Message, "Data Adapter Wizard"); } }
private DataTable GetSQLTable(CustomListData data) { IngresConnection con = GetConnection(data); data.Properties.TryGetValue("SQLStatement", StringComparison.OrdinalIgnoreCase, out var SQLStatement); IngresDataAdapter da = new IngresDataAdapter(new IngresCommand(SQLStatement, con)); DataTable sqlresult = new DataTable(); da.Fill(sqlresult); con.Close(); da.Dispose(); return(sqlresult); }
private void read() { this.dt = new System.Data.DataTable(); IngresConnection con = new IngresConnection(Login.myConnectionString); string query = "select * from read_rol"; IngresCommand comm = new IngresCommand(query, con); con.Open(); IngresDataAdapter adapt = new IngresDataAdapter(comm); adapt.Fill(this.dt); con.Close(); this.metroGrid1.DataSource = this.dt; adapt.Dispose(); }
//public DataAdapterWizard() : this(new IngresDataAdapter(), null) //{ //} public DataAdapterWizard( IngresDataAdapter adapter, System.ComponentModel.Design.IDesignerHost host) { Form dlgWelcome = new DataAdapterWizardWelcomeForm(); DataAdapterWizardGenerateForm dlgGenerate= null; DialogResult result = DialogResult.OK; //goto debugLabel; ShowWelcome: result = dlgWelcome.ShowDialog(); if (result == DialogResult.Cancel) // if Cancel button, return return; //debugLabel: ConnectionEditor connectionEditor = new ConnectionEditor(adapter, host); if (dlgGenerate == null) dlgGenerate = new DataAdapterWizardGenerateForm(adapter.SelectCommand); //ShowGenerate: result = dlgGenerate.ShowDialog(); if (result == DialogResult.Cancel) // if Cancel button, return return; // update the SelectCommand with the entry from the form's text if (result == DialogResult.Retry) // if Back button, go back one goto ShowWelcome; adapter.SelectCommand.CommandText = dlgGenerate.CommandText; try { TableMappings.Generate(adapter); } catch (Exception ex) { MessageBox.Show( "Could not generate DataAdapter's TableMappings.\n" + ex.Message, "Data Adapter Wizard"); } }
protected override IComponent[] CreateComponentsCore(IDesignerHost host) { const string prefix = VSNETConst.shortTitle; // "Ingres" IContainer designerHostContainer = host.Container; ArrayList newComponents = new ArrayList(); ArrayList newCommandComponents = new ArrayList(); string name; IngresConnection connection; IngresCommand providerCommand; if (designerHostContainer == null) // safety check return null; IngresDataAdapter dataAdapter = new IngresDataAdapter(); // Once a reference to an assembly has been added to this service, // this service can load types from names that // do not specify an assembly. ITypeResolutionService resService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); System.Reflection.Assembly assembly = dataAdapter.GetType().Module.Assembly; if (resService != null) { resService.ReferenceAssembly(assembly.GetName()); // set the assembly name to load types from } name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, "DataAdapter"); try { designerHostContainer.Add(dataAdapter, name); newComponents.Add(dataAdapter); } catch (ArgumentException ex) { string exMsg = ex.ToString() + "\nRemove IngresDataAdapter component '" + name + "'" + " that is defined outside of the designer. "; MessageBox.Show(exMsg, "Add " + name + " failed"); return null; } string [] commandName = new String [] { "SelectCommand", "InsertCommand", "UpdateCommand", "DeleteCommand", }; providerCommand = new IngresCommand(); // SELECT newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.SelectCommand = providerCommand; providerCommand = new IngresCommand(); // INSERT newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.InsertCommand = providerCommand; providerCommand = new IngresCommand(); // UPDATE newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.UpdateCommand = providerCommand; providerCommand = new IngresCommand(); // DELETE newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.DeleteCommand = providerCommand; // invoke the wizard to create the connection and query // pass VS.NET IDesignerHost host so we can add Connection DataAdapterWizard wizard = new DataAdapterWizard(dataAdapter, host); // The DataAdapterWizard called the ConnectionEditor and // gave the Wizard and Editor a chance to create the Connection // object and SELECT statement, or to cancel out. // If not cancelled, add the Connection object to // the VS.NET component tray if not already done. if (dataAdapter.SelectCommand != null && dataAdapter.SelectCommand.Connection != null) { connection = dataAdapter.SelectCommand.Connection; name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, "Connection"); //add the connection to the VS.NET component tray designerHostContainer.Add(connection, name); } // add the four Command objects (each with a unique name) // to the designer's components tray for (int i=0; i<4; i++) { name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, commandName[i]); designerHostContainer.Add( (IComponent) newCommandComponents[i], name); } // end for loop thru command components string s = "Creating component list for "+ this.GetType() +"?\n"; return (IComponent[])(newComponents.ToArray(typeof(IComponent))); //return base.CreateComponentsCore(host); }
CreateComponentsCore(IDesignerHost host) { const string prefix = VSNETConst.shortTitle; // "Ingres" IContainer designerHostContainer = host.Container; ArrayList newComponents = new ArrayList(); ArrayList newCommandComponents = new ArrayList(); string name; IngresConnection connection; IngresCommand providerCommand; if (designerHostContainer == null) // safety check { return(null); } IngresDataAdapter dataAdapter = new IngresDataAdapter(); // Once a reference to an assembly has been added to this service, // this service can load types from names that // do not specify an assembly. ITypeResolutionService resService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); System.Reflection.Assembly assembly = dataAdapter.GetType().Module.Assembly; if (resService != null) { resService.ReferenceAssembly(assembly.GetName()); // set the assembly name to load types from } name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, "DataAdapter"); try { designerHostContainer.Add(dataAdapter, name); newComponents.Add(dataAdapter); } catch (ArgumentException ex) { string exMsg = ex.ToString() + "\nRemove IngresDataAdapter component '" + name + "'" + " that is defined outside of the designer. "; MessageBox.Show(exMsg, "Add " + name + " failed"); return(null); } string [] commandName = new String [] { "SelectCommand", "InsertCommand", "UpdateCommand", "DeleteCommand", }; providerCommand = new IngresCommand(); // SELECT newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.SelectCommand = providerCommand; providerCommand = new IngresCommand(); // INSERT newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.InsertCommand = providerCommand; providerCommand = new IngresCommand(); // UPDATE newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.UpdateCommand = providerCommand; providerCommand = new IngresCommand(); // DELETE newCommandComponents.Add(providerCommand); providerCommand.DesignTimeVisible = false; dataAdapter.DeleteCommand = providerCommand; // invoke the wizard to create the connection and query // pass VS.NET IDesignerHost host so we can add Connection DataAdapterWizard wizard = new DataAdapterWizard(dataAdapter, host); // The DataAdapterWizard called the ConnectionEditor and // gave the Wizard and Editor a chance to create the Connection // object and SELECT statement, or to cancel out. // If not cancelled, add the Connection object to // the VS.NET component tray if not already done. if (dataAdapter.SelectCommand != null && dataAdapter.SelectCommand.Connection != null) { connection = dataAdapter.SelectCommand.Connection; name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, "Connection"); //add the connection to the VS.NET component tray designerHostContainer.Add(connection, name); } // add the four Command objects (each with a unique name) // to the designer's components tray for (int i = 0; i < 4; i++) { name = DesignerNameManager.CreateUniqueName( designerHostContainer, prefix, commandName[i]); designerHostContainer.Add( (IComponent)newCommandComponents[i], name); } // end for loop thru command components string s = "Creating component list for " + this.GetType() + "?\n"; return((IComponent[])(newComponents.ToArray(typeof(IComponent)))); //return base.CreateComponentsCore(host); } // CreateComponentsCore
internal ConnectionEditor( IngresDataAdapter adapter, System.ComponentModel.Design.IDesignerHost host) { if (adapter != null && adapter.SelectCommand != null && adapter.SelectCommand.Connection != null) connection = adapter.SelectCommand.Connection; else connection = new IngresConnection(); // format the connection string in key/value pairs nv = ConnectStringConfig.ParseConnectionString( connection.ConnectionString); // the editor will update the key/value pairs Form dlgConnection = new ConnectionEditorForm(nv); DialogResult result = dlgConnection.ShowDialog(); if (result == DialogResult.Cancel) // if Cancel button, return { //MessageBox.Show("Connection DialogResult.Cancel", "ConnectionEditor"); return; } // else (result == DialogResult.OK) // if Next button, go on // rebuild the updated key/value pairs back into a connection string connection.ConnectionString = ConnectStringConfig.ToConnectionString(nv); // connect the Connection object to the four Adapter commands if (adapter != null) { if (adapter.SelectCommand != null) adapter.SelectCommand.Connection = connection; if (adapter.InsertCommand != null) adapter.InsertCommand.Connection = connection; if (adapter.UpdateCommand != null) adapter.UpdateCommand.Connection = connection; if (adapter.DeleteCommand != null) adapter.DeleteCommand.Connection = connection; } }