Link to home
Start Free TrialLog in
Avatar of net_susan
net_susan

asked on

dr = cmd.ExecuteReader()

I have an error on this line:

 dr = cmd.ExecuteReader()

Incorrect syntax near '='.

What's wrong with my code?

Private Sub verifycus()
  Dim objConn As New SqlConnection("Server=myhost; Initial Catalog=mydb; User ID=myid; Password=mypw")
        objConn.Open()
        try
        dim VEmail, VGPassword
        Dim cmd As New SqlCommand("Select * FROM CustomerInfo WHERE Email= '" &VEmail &"' AND VGPassword = "&VPassword, objconn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader()
        While dr.Read
            Response.Write(dr.Item("Email"))
        End While
         dr.Close
               finally
               objConn.Close()
               objConn.Dispose()
               end try
 End Sub
ASKER CERTIFIED SOLUTION
Avatar of Jason Scolaro
Jason Scolaro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brdrok
brdrok

Perhaps a typo?

Dim cmd As New SqlCommand("Select * FROM CustomerInfo WHERE Email= '" &VEmail &"' AND VGPassword =  ' " & VPassword & " ' ", objconn)
Avatar of net_susan

ASKER

Scolja,

BC30451: Name 'Email' is not declared.
net_susan,

I don't have "Email" anywhere, just hanging out... maybe you forgot the V in front of it on this line?

cmd.Parameters.Add(New SqlParameter("@email", VEmail))

-- Jason
you probably just need to initialize dr with 'New'.  

Dim dr As New SqlDataReader
Dim cmd As New SqlCommand("Select * FROM CustomerInfo WHERE Email= '" &VEmail &"' AND VGPassword = "&VPassword, objconn)

on this line, why do you have double quotes before &VEmail? should just be

WHERE Email = " & VEmail & " AND VGPassword = " & VPassword, objConn)
craskin,

Actually, you can't instantiate a SqlDataReader, it has to be assigned.

-- Jason
Jason,

I must have messed up somewhere?

Private Sub verifycus()
Dim objConn As New SqlConnection("Server=myhost; Initial Catalog=mydb; User ID=myid; Password=mypw")
        objConn.Open()
               try
        dim VEemail, VPassword
Dim cmd As New SqlCommand("SELECT * FROM CustomerInfo WHERE Email= @VEemail AND VGPassword = @Vpassword", objconn)
cmd.Parameters.Add(New SqlParameter("@email", VEemail))
cmd.Parameters.Add(New SqlParameter("@VGpassword", VPassword))
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader()
        While dr.Read
            Response.Write(dr.Item("Email"))
        End While
         dr.Close
               finally
               objConn.Close()
               objConn.Dispose()
               end try
 End Sub
net_susan,

Well, from looking at this code... I'm not sure what you're trying to do... you declare your two variables VEemail and VPassword immediately before the New SqlCommand() line.  But then you pass those two variables into the SQL, but they're going to be blank, right?  You haven't assigned a value to them.....

So I'm not sure how you expect to receive any results.  Maybe you can clear this up for me....

-- Jason
Sorry. I'm passing them from the previous page (or at least trying to).

Protected Sub signinSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("next.aspx?VEemail='"+syEmail.Text +"'&VPassword='"+syPassword.Text+"'")
End Sub

That page works.
Then you need to retrieve them on your new page:

Dim VEemail As String = Request.QueryString("VEemail")
Dim VPassword As String = Request.QueryString("VPassword")

Those 2 lines should replace this one:

dim VEemail, VPassword

-- Jason
Thanks, new q coming soon.  :)