Hi All just thought i would post this as i have just spent a bout an hour trying to work out why it would not work in my current project.
I have a a function to create a data table and return it.
Public Function SQL2DataTable(ByVal sql As String)
Dim SqlCon1 As String = "Data Source=sprintsql;Initial Catalog = database ;Integrated Security=SSPI;"
Dim dt As New DataTable
Dim da As New SqlClient.SqlDataAdapter(sql, SqlCon1)
da.Fill(dt)
da.Dispose()
Return dt
End Function
This is called like this
Dim dt As DataTable = SQL2DataTable(sql)
Unable to cast object of type 'System.Data.DataTable' to type 'Excel.DataTable'.
After a lot of frustration i found it was cause by having Imports Excel declared at the beginning Hope this saved you some time.
No comments:
Post a Comment