Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Upload .xls file from client's machine to SQL Server table


Upload .xls file from client's machine to SQL Server table

Reply
  #1 (permalink)  
Old 08-09-05, 02:40 PM
bubberz bubberz is offline
New Member
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Upload .xls file from client's machine to SQL Server table

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"
Else
If getmyFile.ContentLength = 0 Then
Label2.Text = "Cannot upload zero length File"
Else
Dim ServerFileName As String = Path.GetFileName(myfile.PostedFile.FileName)
getmyFile.SaveAs("C:\TestSaving\" & ServerFileName)
Label2.Text = "Successful upload to C:\TestSaving\" & ServerFileName
sCon1.Open()
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)
Try
cmd.ExecuteNonQuery()
err = "Select @@Error"
If err <> 0 Then
Label4.Text = err.ToString()
Else
Label4.Text = "No Error...line 91!"
End If
Catch ex As Exception
Label2.Text = "Line 82 Error Updating Table: "
Label2.Text &= ex.Message
Finally
sCon1.Close()
End Try
End If

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!!!!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP upload prob minority ASP 1 06-27-05 08:35 AM
move files around an ftp server, with php file upload script? wapchimp PHP 2 12-19-04 07:27 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 01:03 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.