You may try this code:
private void Button1_Click(System.Object sender, System.EventArgs e)
{
Excel.Application xlApp = default(Excel.Application);
Excel.Workbook xlWorkBook = default(Excel.Workbook);
//Excel Application workbooks
Excel.Worksheet xlWorkSheet = default(Excel.Worksheet);
Excel.Range xlRange = default(Excel.Range);
int[] array = new int[646];
int i = 0;
long ra = 0;
string oradb = "Data Source=oracle;User Id=test;Password=123";
xlApp = new Excel.ApplicationClass();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Open("C:\\excel_file.xls");
xlWorkSheet = xlWorkBook.Worksheets("sheet1");
xlRange = xlWorkSheet.Columns("E");
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
Interaction.MsgBox("open");
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
for (i = 2; i <= 647; i++) {
array[i - 2] = xlRange.Cells(i).value;
cmd.CommandText = "insert into typlist (baunr) values('" + xlRange.Cells(i).value + "')";
ra = cmd.ExecuteNonQuery();
}
Interaction.MsgBox("Records Inserted " + ra);
conn.Dispose();
xlWorkBook.Close();
xlApp.Quit();
xlApp = null;
}
DOT NET
Basitarif, if this helps please login to Mark As Answer. | Alert Moderator