Error using SQLDataReader
I'm getting the following error at the ' reader = cmd.ExecuteReader() ' line of the code below:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Here's the code:
VB Code:
Dim oSQLConn As SqlConnection
Dim sql As String
Dim cmd As SqlCommand
Dim reader As SqlDataReader
sql = "select column_name from information_schema.columns where table_name='selfserve_receipt_item_maillist"
oSQLConn = New SqlConnection("Data Source=RMSDEVSQL1;Initial Catalog= SelfserveDB;user id=kiwisql;Password=fruitcake")
cmd = New SqlCommand(sql, oSQLConn)
oSQLConn.Open()
reader = cmd.ExecuteReader()
I'm somewhat new to ADO.NET (what the heck happen to recordsets!) so I'm not used to working with SQLDataReader. Any help would be appreciated.
Re: Error using SQLDataReader
Do this:
VB Code:
Try
reader = cmd.ExecuteReader()
Catch sqlEx as SQLException
MessageBox.Show sqlEx.ToString
End
The message box will give you the exact error as reported by the connection. Post what it says and someone should be able to give you a better idea how to fix it.
-tg
Re: Error using SQLDataReader
Without knowing the info Technome spoke of, I would venture a guess that in your sql string you have a single quote on one side of the table name, and not the other.
Bill
Re: Error using SQLDataReader
Yep. That was it. Nothing wrong with the code aside from that. I'm just not thinking today! Thanks.