ExecuteReader: Connection property has not been initialized.

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
 
K

Karl

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top