0

im trying to compare a value that a user can input in a txt box to a record in a database.

for example i have a txt box which has id as txtStudId. now i have a db which has already been linked to the form using the access data source control.

in the database, there exists a student table, where the Stud_ID field contains student id's against which i have to compare.

so when i enter say s112233 in the txt box nd click on a button, say btnLogin, how do i compare this with Stud_ID in the student table?
im lost.....any help will be appreciated.

2
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by __avd
0
....
qry=select * from tablename where col1='" + text1.text + "' and col2='" + text2.text + "'";
....
0

im sorry im not familiar with c# syntax. i see there r some sql statements aswel. im not familiar with this too. im using visual web develper and using an access database with access data source control

0

I presume that your project uses MS-SQL Server Database.

Sub Button1_Click(....) 
        Dim cn as new System.Data.SqlClient.SqlConnection("your connection string")
        Dim qry as String
        qry="select username from login where username='" & TextBox1.Text & "' and password='" & TextBox2.Text & "'"

        Dim cmd as new System.Data.SqlClient.SqlCommand(qry,Cn)
        Dim oRet as Object
        cn.Open()
        oRet=cmd.ExecuteScalar()
        cn.Close()

         if ISDBNull(oRet) then
               .... No - Match
          else
              ... Match
          End if
     .....
     ....
   End Sub
0

Code snippet to use access db.

Sub Button1_Click(....) 
        Dim cn as new System.Data.OleDb.OledbConnection("your connection string")
        Dim qry as String
        qry="select username from login where username='" & TextBox1.Text & "' and password='" & TextBox2.Text & "'"

        Dim cmd as new System.Data.OleDb.OledbCommand(qry,Cn)
        Dim oRet as Object
        cn.Open()
        oRet=cmd.ExecuteScalar()
        cn.Close()

         if ISDBNull(oRet) then
               .... No - Match
          else
              ... Match
          End if
     .....
     ....
   End Sub
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.