Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i m making electronic paper system
how can i compare textbox fields with SQL database values on my login button?
Posted
Comments
Casey Sheridan 5-Jan-13 8:39am    
Do you have any knowledge of SQL or are you looking for complete code?

How can i compare textbox fields with SQL database values on my login button?
Steps:
1. On login button press, raise the click event. Write your comparison code here in this click handler.
2. Now, using ADO.NET, connect to database. Form a query for comparison of the value in DB
3. Run the query and get back the result
4. Take action based on the result returned.

Few references that would help:
MSDN: Accessing Data with ADO.NET[^]
Using ADO.NET for beginners[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
 
Share this answer
 
Comments
Espen Harlinn 6-Jan-13 9:25am    
Nice links :-D
Sandeep Mewara 6-Jan-13 10:11am    
Thanks Espen.
Wendelius 6-Jan-13 10:57am    
Good examples!
VB
con.con_open()

        Dim cmdlogin As New SqlCommand(("SELECT * FROM users WHERE user_name='" & _
                                            txtuname.Text & "' and password='" & _
                                            txtpassword.Text & "'"), con.con)
        Dim dalogin As New SqlDataAdapter
        Dim dslogin As New Data.DataSet
        dalogin.SelectCommand = cmdlogin
        cmdlogin.ExecuteNonQuery()
        dslogin.Clear()
        dalogin.Fill(dslogin, "users")


        If dslogin.Tables(0).Rows.Count > 0 Then

        Else
            
        End If

'--------------------or

        if txtusername.text=dslogin.Tables(0).Rows(0).Item(0).ToString then

        else

        end if

'--------------------

        con.con_close(
 
Share this answer
 
SQL database values on my login button
Please don't do this yourself, use ASP.NET Authentication[^].

Security is a thorny issue which requires an in depth understanding of a wide range of technologies. ASP.Net provides authentication and authorization out of the box, so there is no need to implement this yourself.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Wendelius 6-Jan-13 10:58am    
Good point!
Espen Harlinn 6-Jan-13 10:59am    
Thank you, Mika :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900