Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bubberz
Constraint Violating Yak Guru
289 Posts |
Posted - 2005-08-11 : 17:39:18
|
I'm trying to do the following:1. Allow user to Upload a .xls file from their machine2. Take the rows in this .xls file and insert every row into a table on the DB serverI can select this one file (exceltest.xls) that I've been using to upload, and it saves the .xls file records to the DB table and the records are getting built. THIS IS GOOD! I've placed a PK in the table, so I can see the records increasing w/o question. Problems though are:If I update this exceltest.xls file with new records, the new records aren't getting updated to the db server table. For example, I first had the three rows of "First", "Second", "Third" in the .xls file. When I add a 4th and 5th record of "Fourth" and "Fifth", those don't show in the DB table.Now, if I try another .xls file (basically I copied and renamed the first one to exceltest1.xls), I get:Line 82 Error Updating Table: OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. [OLE/DB provider returned message: The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.] OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IColumnsInfo::GetColumnsInfo returned 0x80004005: ].The code is:Dim getmyFile As HttpPostedFile = myfile.PostedFileLabel2.Text = "Line 76"If IsNothing(getmyFile) ThenLabel2.Text = "Please select a file to upload"Label2.Text = "Line 78"ElseIf getmyFile.ContentLength = 0 ThenLabel2.Text = "Cannot upload zero length File"ElseDim ServerFileName As String = Path.GetFileName(myfile.PostedFile.FileName)Server.MapPath("//dbserver")getmyFile.SaveAs("C:\TestSaving\" & ServerFileName)Label2.Text = "Successful upload to C:\TestSaving\" & ServerFileNamesCon1.Open()Dim strSQL As StringDim err As StringstrSQL = "Insert into ExcelImport Select * FROM OPENROWSET"strSQL &= "('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=C:\TestSaving\" & ServerFileName & ";"""strSQL &= "HDR = YES ','SELECT * FROM [Sheet1$]')"Label3.Text = strSQL.ToString()Dim cmd As New SqlCommand(strSQL, sCon1)Trycmd.ExecuteNonQuery()Catch ex As ExceptionLabel2.Text = "Line 82 Error Updating Table: "Label2.Text &= ex.MessageFinallysCon1.Close()End TryEnd IfEnd IfMy question is do I need to delete this file after it's been uploaded and the records have been built to the table?I do have a folder on dbserver that's shared: C:\TestSavingThanks for the help. I'm almost there! |
|
|
|
|
|
|