PDA

View Full Version : Upload .xls file to SQL Server


bubberz
08-05-2005, 09:56 PM
I got so far as to take a file from my local machine to another directory on my C: drive:

Dim getmyFile As HttpPostedFile = myfile.PostedFile
If IsNothing(getmyFile) Then
Label2.Text = "Please select a file to upload"
Label2.Text = "Line 78"
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
End If
End If

...............now, what I need to do is take an .xls file and allow users to upload that into a specific table.
Any suggestions or samples/articles are more than welcome!

Thanks!

miranda
08-18-2005, 11:05 PM
http://www.codeproject.com/aspnet/fileupload.asp is an article on uploading and saving info to database. Is that what you were looking for? or do you want to save the entire .xls file in a database table?

bubberz
08-18-2005, 11:17 PM
miranda,

Thanks for the reply!

I just want to take whatever rows are in the sheet, and append them to an existing table. So, for instance, if the sheet1 in the .xls file has 15 rows/records, and the table on the DB server has 10, once the user uploaded the .xls file's data, the DB server's table would now have 25 records.

Thanks!

miranda
08-19-2005, 03:37 AM
ok, so then basically what you want to do is upload the .xls file, connect to it, read the information and insert it into the database table.

This Microsoft KB article (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311731) explains how to connect to an excel file using ado.net.

All you have left after that is inserting the rows into the database.