the following example connects to the Oracle database (name) in C #, reads data from the table (tablename), and writes data to excel.
string cnstring = "provider = msdaora.1; Data Source = Name;";
cnstring = cnstring + "User ID = username; Password = password ";
try
{< br> oledbconnection Cn = new oledbconnection (cnstring);
CN. open ();
try
{< br> string S = "select * from name. tablename ";
oledbcommand cmd = new oledbcommand (S, CN);
oledbdatareader DR = cmd. executereader ();
excel. application xlapp = new excel. application ();
If (xlapp = NULL) {MessageBox. Show ("can't open excel! "); Return ;}< br> xlapp. application. workbooks. add (true);
int ROW = 2, fieldcount;
fieldcount = dr. fieldcount;
for (INT Col = 0; Col while (dr. read ()
{< br> for (INT Col = 0; Col xlapp. cells [row, Col + 1] = dr. getvalue (COL ). tostring ();
row ++;
}< br> xlapp. visible = true;
xlapp = NULL;
}< br> catch (exception ex) {MessageBox. show (ex. message) ;}< br> finally {CN. close () ;}< BR >}< br> catch (exception ex) {MessageBox. show (ex. message) ;}< BR >}