[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to user textbox value in a query for VB.NET

Posted on 2005-05-11
10
Medium Priority
?
280 Views
Last Modified: 2010-04-23
Hi,
I need to use two textbox values for the following query..
I am having syntax error problem..
Pls provide a correct syntax..

Dim dass As New OleDbDataAdapter("SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID= " & user_id.Text & " PASSWORD =" & user_password.Text", cnss)

In the MS Access database UST id is number and PASSWORD is text.

Thanks.
_Esam
0
Comment
Question by:_Esam
  • 5
  • 3
  • 2
10 Comments
 
LVL 7

Expert Comment

by:davidrichardson
ID: 13976592
='" & user_id.Text .Text & "'"
0
 

Author Comment

by:_Esam
ID: 13976637
Well I tried this:

Dim dass As New OleDbDataAdapter("SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID ='" & user_id.Text & "'" PASSWORD = " & user_password.Text &", cnss)

It is saying valid continuation needed at > PASSWORD

_Esam
0
 
LVL 7

Accepted Solution

by:
davidrichardson earned 160 total points
ID: 13976672
Sorry Try

SELECT  SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = '" & user_id.Text & "' AND PASSWORD = '" & user_password.Text & "'"
0
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!

 
LVL 8

Expert Comment

by:doobdave
ID: 13976691
Hi Esam,

davidrichardson's answer is correct except that he mistakenly used user_id.text rather than user_password.text.

Your problem appears to be that you don't have single quotes in the SQL statement around the password field (which is a text field).
So in pure SQL the statement should look something like:

SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = 1 AND PASSWORD = 'password'

Converting that back to your VB code, should result ni the following:

Dim dass As New OleDbDataAdapter("SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID= " & user_id.Text & " PASSWORD = '" & user_password.Text & "'", cnss)

HTH
David
0
 
LVL 8

Assisted Solution

by:doobdave
doobdave earned 80 total points
ID: 13976699
As the User ID is a number you do not need the single quotes around that value...
0
 
LVL 7

Expert Comment

by:davidrichardson
ID: 13976714
doobdave

>>davidrichardson's answer is correct except that he mistakenly used user_id.text rather than user_password.text.

Where?
0
 

Author Comment

by:_Esam
ID: 13976756
Ok.

I tried this:

Sub VerifyUser()
        Dim cnss As New OleDbConnection
        Dim sss As String = Server.MapPath("UST.mdb")
        cnss.ConnectionString = "provider =Microsoft.Jet.OLEDB.4.0; data source = " + sss
        cnss.Open()
        Dim dass As New OleDbDataAdapter("SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID= " & user_id.Text & " PASSWORD = '" & user_password.Text & "'", cnss)' ='" & user_id.Text .Text & "'"
        Dim dsss As New DataSet
        dass.Fill(dsss, "USERDATA")
        cnss.Close()

    End Sub


Public Sub submit_click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        VerifyUser()

        Session("user_name") = Server.UrlEncode(user_id.Text)
        Session("user_password") = Server.UrlEncode(user_password.Text)
        Response.Redirect("CoursePlanner.aspx")
    End Sub

Right now I am simply trying to figure out if it is working...

BUt got this error:
Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'UST_ID= 1204 PASSWORD = 'nymo''.

In my MS Access database UST_ID is number and PASSWORD is text.

_Esam
0
 

Author Comment

by:_Esam
ID: 13976772
WHere is the AND?

_Esam
0
 

Author Comment

by:_Esam
ID: 13976790
OK it worked:
Dim dass As New OleDbDataAdapter("SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID= " & user_id.Text & " AND PASSWORD = '" & user_password.Text & "'", cnss)
_Esam
0
 

Author Comment

by:_Esam
ID: 13976823
I accepted davidrichardson's answer since that is valid with doobdave's addition of  user_id being a number in my database.

Thanks..
_Esam
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

872 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