Trying to import specific rows from excel to sql table. But: System.Data.OleDb.OleDbException: No value given for one or more required parameters.
Posted on 2013-11-25
I have workable code to import excel data into sql table, but only as [Sheet1$]. But, I'm trying to choose specific rows to be imported like [Sheet1$A3:C3]. And, of course not working, and getting an error: System.Data.OleDb.OleDbException: No value given for one or more required parameters.
So, I would like someone to check if this is actual correct procedure, or something else...Or, maybe my approach is totally wrong.
Private strConnection As String = "<MyServerConnection>"
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim path As String = fileuploadExcel.PostedFile.FileName
Dim excelConnectionString As String = (Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") & path) + ";Extended Properties=Excel 12.0;Persist Security Info=False"
Dim excelConnection As New OleDbConnection(excelConnectionString)
Dim cmd As New OleDbCommand("Select [ID],[FirstName],[SecondName] from [Sheet1$A3:C3]", excelConnection)
Dim dReader As OleDbDataReader
dReader = cmd.ExecuteReader()
Dim sqlBulk As New SqlBulkCopy(strConnection)
sqlBulk.DestinationTableName = "test"
Thank you in advance for help.