importing data from an excel sheet to sql server express using c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Narz1986
    New Member
    • Dec 2008
    • 10

    #1

    importing data from an excel sheet to sql server express using c#

    hi....i m fairly new to c#.net...i m trying to import data from an excel file to sql server using c#.....below here is my code....when i m executing this code i m getting an exception "ODBC CALL FAILED" i m not able to figure out where i hve gone wrong...so if any one could guide me i wil b thankful....




    private void Import_btn_Clic k(object sender, EventArgs e)
    {
    try
    {
    string excelConnection String = @"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" + openFile.FileNa me + ";Extended Properties=Exce l 8.0";
    // Create Connection to Excel Workbook
    OleDbConnection connection = new OleDbConnection (excelConnectio nString);
    connection.Open ();
    OleDbCommand command = new OleDbCommand("I NSERT INTO[ODBC;DRIVER ={SQLEXPRESS};S ERVER=DASSDP-12\\SQLEXPRESS; DATABASE=mIO;Tr usted Connection=Yes].Brand SELECT Brand FROM [BrandDefinition $A8:E9999]", connection);
    command.Execute NonQuery();
    connection.Clos e();
    }
    catch (Exception ex)
    {
    MessageBox.Show (ex.Message);
    }
    finally
    {
    }

    }
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    #2
    OleDB provider for MS excel ?
    Dont think it will work, i guess u will have to use System.IO or Excel library for that.

    Comment

    • Narz1986
      New Member
      • Dec 2008
      • 10

      #3
      yes Oledb provider for excel.......
      could u tel me if there is any other method.....

      Comment

      Working...