I have the following code:
I am getting the error ExecuteReader: Connection property has not been initialized.
Any ideas?
Thanks
Code:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim conUsers As SqlConnection
Dim SqlCommand As SqlCommand
Dim strConnection As String
strConnection = ConfigurationManager.ConnectionStrings("quickbabysitConnectionString").ConnectionString
conUsers = New SqlConnection(strConnection)
SqlCommand = New SqlCommand("SELECT [BookingFee] FROM [ParentsMembership] WHERE ([EmailAddress] = @EmailAddress)")
SqlCommand.Parameters.AddWithValue("@EmailAddress", Session("UserID"))
conUsers.Open()
Dim dtrReader As SqlDataReader = SqlCommand.ExecuteReader()
If dtrReader.HasRows Then
'if you retrieve more than one row, you need the next line. If only one row, you can leave it out.
'I will comment it out because you are returning only one row, especially with "TOP 1"
'while dtrReader.Read()
txtFee.Text = dtrReader("BookingFee")
'end while
Else
Response.Write("No customer found for the supplied email.")
End If
dtrReader.Close()
conUsers.Close()
End Sub
I am getting the error ExecuteReader: Connection property has not been initialized.
Any ideas?
Thanks