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.

....
qry=select * from tablename where col1='" + text1.text + "' and col2='" + text2.text + "'";
....

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

Which language you own?

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

using access database and not sql....

thanks....

do u know how u kud do it with access database?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.