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
{
}
}
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
{
}
}
Comment