Click here to Skip to main content
13,347,671 members (49,848 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am currently creating a login form in visual c#, but i am facing problem on how to check if the user input username and password match with the USERNAME and PASSWORD in mysql table. I want the user to input a username and password in the text box then the program will search the table and if the username and password found. the program will display the main form, if not display error message.

Please help on how to accomplish this task i am beginner in c# or please help if where can i find a references or resources in c# programming and mysql as database.

Posted 13-Oct-12 3:53am
Wes Aday 13-Oct-12 9:01am
How is this a problem? Get the username and password from the user, connect to your database, and query the database to see if the username and password are valid.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

HI This will help you copy and paste it

SqlConnection con = new SqlConnection("Connection");
            SqlCommand cmd = new SqlCommand("select pwd,userName from LoginTable",con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            if (txtPassword.Text == dt.Rows[0]["pwd"].ToString() && txtUserName.Text == dt.Rows[0]["userName"].ToString())
            //Error display Msg
Wes Aday 13-Oct-12 9:11am
And this will allow the OP to connect to a MySql database?
Himanshu Yadav 13-Oct-12 9:12am
OP means
Himanshu Yadav 13-Oct-12 9:13am
asking regarding Connection String
Himanshu Yadav 13-Oct-12 9:18am
is this working ?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 13 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100