Answered by:
Check my error,,while I'm reading an excel file

Question
-
User-859173698 posted
Dear all,,
I have been used this code but its doesn't work,,
this code should read an excel file then store it into a table in my database (SQLserver DB),,
could you help,,
thanks in advance,,
Imports
System.Data Partial Class _DefaultInherits System.Web.UI.PageMyConnection =
New System.Data.OleDb.OleDbConnection _ ("provider=Microsoft.Jet.OLEDB.4.0; Data Source='c:\ADMIN.xls'; Extended Properties=Excel 8.0;")MyCommand =
New System.Data.OleDb.OleDbDataAdapter _ ("select * from [Sheet1$]", MyConnection)MyCommand.TableMappings.Add(
"Table", "TestTable") DtSet = New System.Data.DataSetMyCommand.Fill(DtSet)
GridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
Catch ex As ExceptionMsgBox(ex.ToString)
End Try End SubEnd
ClassWednesday, May 7, 2008 10:38 AM
Answers
-
User1485238302 posted
You can use SqlBulkCopy class to export excel data to sql server database table. This class is available in System.Data.SqlClient namespace.
http://davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 7, 2008 1:39 PM
All replies
-
User1485238302 posted
Do you get any arror?
Wednesday, May 7, 2008 10:54 AM -
User-859173698 posted
Hi,bullpit
Do you get any arror?
Sorry maybe "Check my error " wasn't clear enough
What I want is to ask ,"why the code is not working with me"?
Its should import the data from the excel file into a table in my DB, but , its doesn't do this..
Wednesday, May 7, 2008 12:47 PM -
User1485238302 posted
Its should import the data from the excel file into a table in my DB,Well..thats because you are not pushing it into the db. You are just trying to display it in the gridview.
Wednesday, May 7, 2008 1:08 PM -
User-859173698 posted
I appreciate you,,
How could I push the dataset into the DB?
Thanks in advance
Wednesday, May 7, 2008 1:16 PM -
User1485238302 posted
You can use SqlBulkCopy class to export excel data to sql server database table. This class is available in System.Data.SqlClient namespace.
http://davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, May 7, 2008 1:39 PM -
User-859173698 posted
Thanks alot bullpit,,
There isn't away to insert the dataset into the database, to just add it to my code?
Wednesday, May 7, 2008 3:02 PM