Some code is provided below: C #
Need to reference
Using system. Data. oracleclient;
Using system. Data. sqlclient;
Private void button3_click (Object sender, eventargs e) // import data from sqlserver to Oracle
{
Button3.enabled = false; // prevent multiple clicks
Int temp = 0; // used to determine whether the insert is successful
String sqlstr; // receives the insert statement
Datatable dt = new datatable ();
String SQL = "select * From Dictionary"; // an existing data table in Oracle
Sqldataload sqldata = new sqldataload (); // custom class
Dt = sqldata. orselect (SQL );
String [] col = new string [3]; // used to receive data in no row
If (Dt. Rows. Count> 0)
{
For (INT I = 0; I <DT. Rows. Count; I ++) // loop each row
{
For (Int J = 0; j <DT. Columns. Count; j ++) // loop each column
{
Col [J] = DT. Rows [I] [J]. tostring ();
}
Sqlstr = "insert into tdictionary (Enfield, chfield, method) values (" + strto (COL [0]) + "," + strto (COL [1]) + ", "+ strto (COL [2]) + ")";
Dataconn orconn = new dataconn ();
Temp = orconn. orupdate (sqlstr); // insert data into ORACLE data
}
}
Button3.enabled = true;
If (temp! =-1) MessageBox. Show ("conversion successful !! ");
Else
MessageBox. Show ("Conversion failed !! ");
}
Public String strto (string Str)
{
STR = "'" + STR + "'";
Return STR;
}
Custom class:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Data. oracleclient;
Using system. Data;
Namespace exceltooracletable
{
Class dataconn
{
Public dataconn ()
{
}
Public String connectionstring = "Data Source = Telecom; persist Security info = true; user id = Qiao; Password = Qiao; Unicode = true"; // write a connection string
Public datatable orselect (string Str)
{
Datatable dt = new datatable ();
Oracleconnection conn = new oracleconnection ();
Conn. connectionstring = connectionstring;
Oracledataadapter adapter = new oracledataadapter (STR, Conn );
Try
{
Conn. open ();
Adapter. Fill (DT );
}
Catch (oracleexception ee)
{
}
Finally
{
Conn. Close (); // close the connection
}
Return DT;
}
Public int orupdate (string sqlstr)
{
Oracleconnection conn = new oracleconnection ();
Conn. connectionstring = connectionstring;
Oraclecommand command = new oraclecommand (sqlstr, Conn );
Try
{
Conn. open ();
Return command. executenonquery (); // return the number of Operation rows
}
Catch (oracleexception ee)
{
Return-1; // operation failed
}
Finally
{
Conn. Close (); // close the connection
}
}
Public dataset orselect2 (string Str)
{
Oracleconnection conn = new oracleconnection ();
Conn. connectionstring = connectionstring;
Oracledataadapter adapter = new oracledataadapter (STR, Conn );
Dataset DS = new dataset ();
Try
{
Conn. open ();
Adapter. Fill (DS );
}
Catch (oracleexception ee)
{
// MessageBox. Show ("Connection Failed !!! ");
}
Finally
{
Conn. Close (); // close the connection
}
Return Ds;
}
}
}