importing/exporting excel and SQL database

manared

Well-known member
Joined
Jun 1, 2006
Messages
84
Programming Experience
1-3
I am using vb.net 2005 and SQL 2005. I want to be able to export a SQL table into a Microsoft Excel File using .net. I also want to be able to upload an Excel file and put it into a SQL database. How would I go about doing this? Do I have to convert to CVS or something at all? What's the easiest/best way? Thank you in advance.
 
You should be able to use a query like the following to exprt data into an excel worksheet....

VB.NET:
strSQL = "SELECT * INTO [Sheet1] IN '" & App.Path & _
"\book1.xls' 'Excel 8.0;' FROM TableName"
 
So all I need to do is write that query exactly how it is (changing the table name) and then run an execute query?
When I tried this last time, it says that App is not defined. How do I need to change that?
 
This is my code right now:

VB.NET:
Dim strSQL As String
strSQL = "SELECT * INTO [Sheet1] IN 'C:\book1.xls' 'Excel 8.0;' FROM Issues"
Dim command As New SqlCommand
conn.Open()
command.Connection = conn
command.CommandText = strSQL
command.ExecuteReader()
conn.Close()

The error states "Incorrect syntax near the keyword 'IN'"
 
thanks. going to the SQL server and running the wizard, I can get the data to export to Excel. I have to actually be on the server to do this because I need SP1 on my local machine to do it. I may have to do that at some point. But now I need to figure out how to do it using vb.net, like have the user press a button and then the data just goes to excel. I'm working on the second link you gave me. Trying to figure out how to update it to the 2005 version. I'm just having trouble with the Table.column and table.row in the loops.
 
Back
Top