ExecuteReader: Connection property has not been initialized.

  • Thread starter Thread starter CJM
  • Start date Start date
C

CJM

I'm not sure where I cam going wrong here... I'm getting the runtime error
above, but my code seems reasonable. Am I missing something?

Code Snippet:

oConn = New SqlConnection
oConn.ConnectionString = "Data Source=MyServer;Initial Catalog=TADB;User
Id=TADB;Password=xxx;"
oCmd = New SqlCommand("Exec TA_GetTADetails " & txtTANumber.Text)
oConn.Open()

dgResults.DataSource = oCmd.ExecuteReader()
<=========== error
dgResults.DataBind()

oConn.Close()



Thanks

Chris
 
You aren't associating your command with your connection

oCmd = new SqlCommand("....", oConn) I believe

or after you create the command, you can do
oCmd.Connection = oConn (again, I think)

anyways, that's your problem.. and there are even more ways so solve
it...like:
oCmd = oConn.CreateCommant("EXEC...")

Karl
 
Back
Top