Thanks! I have managed to insert the data during testing to database.
However, i have this problem that I am still facing. I have looked up many tutorials but none work. I will paste my codes here to see if Im doing it the right way.
I need to retrieve 2 things dynamically.
1. Excel File Name
what I did was this:
Dim strFileName As String
strFileName = Path.GetFileName(FileUploadExcel.FileName)
Dim xConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath(FileUploadExcel.PostedFile.FileName) + ";" & _
"Extended Properties=Excel 8.0;"
to get the filename and also the path. but I could not get it to work. Because this path is incorrect, it cannot trace the worksheet name by the name of [Sheet1$] in the excel file.
2. 2nd thing that I need to retrieve dynamically is the worksheet name.
Dim objCommand As New OleDbCommand()
objCommand.Connection = objXConn
'accessing sheet
Dim dtExcelSchema As DataTable
dtExcelSchema = objXConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
For i = 0 To dtExcelSchema.Rows.Count - 1
Dim sheetName As String = dtExcelSchema.Rows(i)("TABLE_NAME").ToString
objCommand.CommandText = "SELECT * FROM [" + sheetName + "]"
Next
da.SelectCommand = objCommand
da.Fill(ds) - error occured here : Command text was not set for the command object.
objXConn.Close()
Now, even though Im able to insert data, but without able to retrieve the 2 important parameters : Excel File Name & the Sheet Name. I am unable to do the SQLBULKCOPY.
Any advise? or my above codes are wrong?
Thank you,.