Recommended Methods
Public void oledboracle_dataset ()
{
String connectionstring = "Data Source = mine; user = sys; Password = sys;"; // write the connection string
Oracleconnection conn = new oracleconnection (connectionstring); // create a new connection
Oraclecommand cmd = new oraclecommand ("select * From fjdl. t_rights", Conn );
Dataset DS = new dataset ();
Oracledataadapter ODA = new oracledataadapter ();
ODA. selectcommand = cmd;
ODA. Fill (DS );
Conn. Close ();
Datagrid1.datasource = Ds. Tables [0]. defaultview;
Datagrid1.databind ();
}
The following are four methods for using dataset, datareader, oledb, and oralceclient:
Public void oledboracle_datareader ()
{
System. Data. oledb. oledbconnection oledb1 = new system. Data. oledb. oledbconnection ();
String sqltext = "select * from Scott. tadmin ";
System. Data. oledb. oledbdatareader reader;
Oledb1.connectionstring = "provider =/" oraoledb. oracle.1/"; user id = system; Password = system; Data Source = Rick ;";
System. Data. oledb. oledbcommand COM = new system. Data. oledb. oledbcommand (sqltext, oledb1 );
Com. Connection. open ();
Reader = com. executereader ();
Datagrid1.datasource = reader;
Datagrid1.databind ();
// This. response. Write (oledbconnection1.connectionstring );
Reader. Close ();
Com. Connection. Close ();
}
Public void oledboracle_dataset ()
{
System. data. oledb. oledbconnection oledb1 = new system. data. oledb. oledbconnection ("provider =/" oraoledb. oracle.1/"; user id = system; Password = system; Data Source = Rick ;");
String sqltext = "select * from Scott. tadmin ";
System. Data. dataset set1 = new dataset ();
System. Data. oledb. oledbdataadapter ada1 = new system. Data. oledb. oledbdataadapter (sqltext, oledb1 );
Ada1.fill (set1, "data1 ");
This. datagrid2.datasource = set1.tables ["data1"]. defaultview;
This. Maid ();
}
Public void oracle_dataset ()
{
System. Data. oracleclient. oracleconnection oracle1 = new system. Data. oracleclient. oracleconnection ("User ID = system; Data Source = Rick; Password = system ");
String sqltext = "select * from Scott. tadmin ";
System. Data. dataset set1 = new dataset ();
System. Data. oracleclient. oracledataadapter ada1 = new system. Data. oracleclient. oracledataadapter (sqltext, oracle1 );
Ada1.fill (set1, "oracle_data1 ");
This. datagrid3.datasource = set1.tables ["oracle_data1"]. defaultview;
This. datagrid3.databind ();
}
Public void oracle_datareader ()
{
System. Data. oracleclient. oracleconnection oracle2 = new system. Data. oracleclient. oracleconnection ();
String sqltext = "select * from Scott. tadmin ";
System. Data. oracleclient. oracledatareader reader;
Oracle2.connectionstring = "User ID = system; user id = system; Data Source = Rick; Password = system ";
System. Data. oracleclient. oraclecommand COM = new system. Data. oracleclient. oraclecommand (sqltext, oracle2 );
Com. Connection. open ();
Reader = com. executereader ();
Datagrid4.datasource = reader;
Datagrid4.databind ();
// This. response. Write (oledbconnection1.connectionstring );
Reader. Close ();
Com. Connection. Close ();
}
Note:
If the local network configuration of remote data is not set
ORA-00162: External dbid length 18 is greater than maximum (16)
The connection name cannot exceed 16 characters
Modification Method
Configuration and migration tools-> net configuration assistant Configuration