Question Unable to cast object of type 'System.Data.DataTable' to type 'Microsoft.Office.Inter

droyce

Member
Joined
Dec 2, 2009
Messages
6
Programming Experience
1-3
I keep getting the following error every time i run this script i cannot find any info why this is happening and how to fix it, any help would be great

Dim plmExcelCon As New System.Data.OleDb.OleDbConnection
Dim cmdLoadExcel As System.Data.OleDb.OleDbDataAdapter
Dim PrmPathExcelFile As String

PrmPathExcelFile = txtImportFileLocation.Text.ToString

plmExcelCon = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + PrmPathExcelFile + ";Extended Properties=Excel 12.0;")

cmdLoadExcel = New System.Data.OleDb.OleDbDataAdapter("select * from [" + txtImportSheetName.Text + "$]", plmExcelCon)

Dim ldExcelDS As System.Data.DataSet

ldExcelDS = New System.Data.DataSet

cmdLoadExcel.Fill(ldExcelDS)

plmExcelCon.Close()

'New
Dim dt As DataTable = ldExcelDS.Tables(0)

For Each row As DataRow In dt.rows
Dim impEID As String = row(txtImportEID.Text)
Dim impVID As String = row(txtImportVID.Text)
Try

cmdINSERT.Parameters("@pldLifeDataEID").Value = impEID
cmdINSERT.Parameters("@pldLifeDataVID").Value = impVID
cmdINSERT.Parameters("@pldLifeDataDateEntry").Value = Date.Now

cnLD.Open()
cmdINSERT.ExecuteNonQuery()
cnLD.Close()

Catch ex As Exception
MessageBox.Show(ErrorToString)
End Try
Next
 
I see no attempt to cast a datatable into some interop object. Please provide the exact line of code the error occurs on and the FULL error messge
 
Back
Top