By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

How to import a Excel files to Sql server database...please send me the code....

P: 2
Hi,
I have a excel file names list in my listbox.
If i click move data.. the listbox excelfiles are imported to
Sqldata base
plese help...its very urgent
Apr 26 '07 #1
Share this Question
Share on Google+
2 Replies


dip_developer
Expert 100+
P: 648
Hi,
I have a excel file names list in my listbox.
If i click move data.. the listbox excelfiles are imported to
Sqldata base
plese help...its very urgent
you can use Excel files as Table.....select data from your Excel files...populate a dataset or datatable....then Insert these data into your SQL Server database tables...

try this code if you use VB.NET

Expand|Select|Wrap|Line Numbers
  1. 'Instantiate your variable
  2. Dim MyAdapter As System.Data.OleDb.OleDbDataAdapter
  3. Dim MyConnection As System.Data.OleDb.OleDbConnection
  4. Dim myDataset As DataSet
Expand|Select|Wrap|Line Numbers
  1. Dim conStr As String = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + myExcelFileName + "; Extended Properties=Excel 8.0;"
  2. Dim mysql As String = "select * from [Sheet1$]" '-------- "Sheet1" is the name of the excel sheet
  3. MyConnection = New System.Data.OleDb.OleDbConnection(conStr)
  4. MyConnection.Open()
  5. MyAdapter = New System.Data.OleDb.OleDbDataAdapter(mysql, MyConnection)
  6. myDataset= New System.Data.DataSet
  7. MyAdapter.Fill(myDataset)
now reading records from myDataset insert records into your Database table
Apr 26 '07 #2

P: 2
Thanks.... i will try this and let u know...
Apr 26 '07 #3

Post your reply

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