Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExecuteReader Error

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
What does this message mean?? Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.

here is my code

<%@ Page Language=&quot;VB&quot; Debug=&quot;true&quot; ContentType=&quot;text/html&quot; ResponseEncoding=&quot;iso-8859-1&quot; %>
<%@ import Namespace=&quot;System.Data.sqlClient&quot; %>
<%@ import Namespace=&quot;System.Data&quot; %>
<%@ import Namespace=&quot;System.Drawing&quot; %>
<%@ import Namespace=&quot;System.Web.HttpCookie&quot; %>
<script runat=&quot;server&quot;>
Public Sub Page_Load(Source as Object, E As EventArgs)
if Not IsPostBack Then
BindData
End If
End Sub
Sub BindData
Dim dbconn As SqlConnection = New SqlConnection(&quot;server=AM1ST_FS1;database=HRINFO;uid=sa;&quot;)
Dim selectCMD As SqlCommand = New SqlCommand(&quot; Select * From phonelist where location = 1st Floor Order by lastName&quot;)
dbconn.open()
fstfloor.DataSource = selectCMD.ExecuteReader()
fstfloor.DataBind()
dbconn.close()
End Sub
 
The command object needs to know the connection to use.
Either
' Assign connection at NEW for Command object
Dim selectCMD As SqlCommand = New SqlCommand(&quot; Select * From phonelist where location = 1st Floor Order by lastName&quot;, dbconn)

OR
'Assign coonection manually before exeute
selectCmd.Connection = dbconn
fstfloor.DataSource = selectCMD.ExecuteReader()
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top