?
Solved

dr = cmd.ExecuteReader()

Posted on 2006-03-28
13
Medium Priority
?
7,964 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:net_susan
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 22

Accepted Solution

by:
Jason Scolaro earned 2000 total points
ID: 16313600
Hi net_susan,

Try this:
Dim cmd As New SqlCommand("SELECT * FROM CustomerInfo WHERE Email= @email AND VGPassword = @password", objconn)
cmd.Parameters.Add(New SqlParameter("@email", VEmail))
cmd.Parameters.Add(New SqlParameter("@password", VPassword))

-- Jason
0
 
LVL 7

Expert Comment

by:brdrok
ID: 16313602
Perhaps a typo?

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

Author Comment

by:net_susan
ID: 16313993
Scolja,

BC30451: Name 'Email' is not declared.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:Jason Scolaro
ID: 16314003
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
0
 
LVL 12

Expert Comment

by:craskin
ID: 16314051
you probably just need to initialize dr with 'New'.  

Dim dr As New SqlDataReader
0
 
LVL 12

Expert Comment

by:craskin
ID: 16314067
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)
0
 
LVL 22

Expert Comment

by:Jason Scolaro
ID: 16314081
craskin,

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

-- Jason
0
 
LVL 1

Author Comment

by:net_susan
ID: 16314160
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
0
 
LVL 22

Expert Comment

by:Jason Scolaro
ID: 16314186
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
0
 
LVL 1

Author Comment

by:net_susan
ID: 16314281
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.
0
 
LVL 22

Expert Comment

by:Jason Scolaro
ID: 16314306
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
0
 
LVL 1

Author Comment

by:net_susan
ID: 16314419
Thanks, new q coming soon.  :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question