"CommandText property has not been initialized" error
Posted: Wed Apr 06, 2016 5:47 pm
Hi, I am passing sql query as a parameter to the function. When i try to execute the code, it is throwing me error "ExecuteReader: CommandText property has not been initialized"
It works fine when i put SQl query in the code and execute. The problem is when I am passing that query as parameter using excel data connector. Below is the code that i have used. Please let me know where might be the issue.
Public Shared Sub TestConnection(query as String)
Dim digitalTracksDT As System.Data.DataTable
Dim conn As New OdbcConnection("DSN=Database_Name")
conn.Open()
System.Console.WriteLine("Database Connection opened ")
Dim digitalTrackGet As New OdbcCommand(query, conn)
Dim adp3 As New OdbcDataAdapter(digitalTrackGet)
adp3.Fill(digitalTracksDT)
System.Console.WriteLine("Data Table filled successfully")
conn.Close()
End Sub
It works fine when i put SQl query in the code and execute. The problem is when I am passing that query as parameter using excel data connector. Below is the code that i have used. Please let me know where might be the issue.
Public Shared Sub TestConnection(query as String)
Dim digitalTracksDT As System.Data.DataTable
Dim conn As New OdbcConnection("DSN=Database_Name")
conn.Open()
System.Console.WriteLine("Database Connection opened ")
Dim digitalTrackGet As New OdbcCommand(query, conn)
Dim adp3 As New OdbcDataAdapter(digitalTrackGet)
adp3.Fill(digitalTracksDT)
System.Console.WriteLine("Data Table filled successfully")
conn.Close()
End Sub