Need to upload .xls file to SQL Server table via ASP.NET app
Here's what I have to do:
1. Allow user to locate a .xls file on their machine
2. Upload this .xls data into an existing table on a remote SQL Server
I can pull the file from my local machine to another directory on the local machien, but can't figure out have to configure the saveas() to save on the remote db server.
It seems you have to save the the db server first on the hard drive, then you can insert the .xls file data into the table.
Here's my code so far that works to save on the local machine to another directory on that local machine:
Dim getmyFile As HttpPostedFile = myfile.PostedFile
If IsNothing(getmyFile) Then
Label2.Text = "Please select a file to upload"
If getmyFile.ContentLength = 0 Then
Label2.Text = "Cannot upload zero length File"
Dim ServerFileName As String = Path.GetFileName(myfile.PostedFile.FileName)
getmyFile.SaveAs("C:\TestSaving\" & ServerFileName)
Label2.Text = "Successful upload to C:\TestSaving\" & ServerFileName
Dim strSQL As String
Dim err As Integer
strSQL = "Insert into ActivityTest Select * FROM OPENROWSET"
strSQL &= "('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\testing.xls;"
strSQL &= "HDR = YES ','SELECT * FROM [Sheet1$]')"
Label3.Text = strSQL.ToString()
Dim cmd As New SqlCommand(strSQL, sCon1)
err = "Select @@Error"
If err <> 0 Then
Label4.Text = err.ToString()
Label4.Text = "No Error...line 91!"
Catch ex As Exception
Label2.Text = "Line 82 Error Updating Table: "
Label2.Text &= ex.Message
Any books that you know of to help with this topic, since I'm sure I'll be doing more of it in the future, will be apppreciated too!
Thanks for the help in advance!!!!
By dhaya in forum Database
Last Post: 08-25-2003, 06:24 PM
Last Post: 04-04-2003, 05:55 PM
By Ralf in forum Database
Last Post: 08-08-2002, 09:58 AM
By Nate in forum Database
Last Post: 05-09-2001, 11:04 AM
By Bharat in forum Database
Last Post: 03-06-2001, 09:42 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL