469,299 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

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_Click(object sender, EventArgs e)
{
try
{
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFile.FileName + ";Extended Properties=Excel 8.0";
// Create Connection to Excel Workbook
OleDbConnection connection = new OleDbConnection(excelConnectionString);
connection.Open();
OleDbCommand command = new OleDbCommand("INSERT INTO[ODBC;DRIVER ={SQLEXPRESS};SERVER=DASSDP-12\\SQLEXPRESS;DATABASE=mIO;Trusted Connection=Yes].Brand SELECT Brand FROM [BrandDefinition$A8:E9999]", connection);
command.ExecuteNonQuery();
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}

}
Dec 2 '08 #1
2 2747
akshaycjoshi
153 100+
OleDB provider for MS excel ?
Dont think it will work, i guess u will have to use System.IO or Excel library for that.
Dec 3 '08 #2
yes Oledb provider for excel.......
could u tel me if there is any other method.....
Dec 3 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Darren | last post: by
9 posts views Thread by jillandgordon | last post: by
3 posts views Thread by Conrad F | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.