Add reference:
Using System. Data. OracleClient;
Here I select an Oracle (Service name (Data Source here is separated from Data Source): GIS user Name (user): gis password (password): gis) your Oracle database has its own name. Please modify it.
I have selected a table named "Pipeline", where "MSFS, BH" are all columns in the table.
Code:
Add a button.
Private void button#click (object sender, EventArgs e)
{
String connection = "Data Source = GIS; user = gis; password = gis"; // password of the Data Source connecting to the database
OracleConnection coon = new OracleConnection (connection); // create a database connection
OracleCommand cmd = new OracleCommand ("select MSFS, BH from Pipeline", coon); // execute data connection. to select all columns, you can set MSFS, change BH to *, that is, "select * from Pipeline"
DataSet ds1;
Ds1 = new DataSet (); // defines a DataSet
OracleDataAdapter da1 = new OracleDataAdapter (cmd); // retrieves a data table
Da1.Fill (ds1); // load data to a data set
DataTable dt = ds1.Tables [0]; // put data into the table
Coon. Close (); // Close the database connection
/// Traverse
//// If the table is empty, return
// The following code can be used to operate a table. if you want to directly display the table, you can directly add the data display code. The if else code below does not need to be used.
If (dt = null)
{
Return;
}
Else
{
For (int I = 0; I <dt. Rows. Count; I ++)
{
}
}
// Display data in the dataGridView
This. Maid = dt. DefaultView;
This. Maid ();
}