Hello there
I am describing how you can read the data you created using mysql server with C#.
I think this is one of the first projects of C# beginners.
As you know, we use various software to use the database we created with Mysql.The C# We use for desktop software is one of them.
Once you have learned to log in using the database, you can develop this project and read other data from the database.
I will tell you step by step how to create a database with MySQL and how to add the data.
If you wish, you can install the database on a remote server and make a licensed login system.
You will reach the following experiences with this topic.
- Creating a project.
- Adding Button
- Adding Textbox
- Adding Labels
- Form design
- Textbox Passwordchar
- Change the element name.
- Button Click Event Control
- If Else Method
- MessageBox Control
- Program Exit Method
- Creating SQL Database
- Creating Table
- Adding data to a database
if you want to download my test database click here
Project Github Link : https://github.com/oguzdelioglu/C--Form-Login-System
Database Name
Enter Your Database Name. Example "teststeemit".
Database Name
Create Table
Create Column
Adding data
DB Connection Codes
private void dbconnect()
{
try
{
conn = "Server=localhost;Database=teststeemit;Uid=root;Pwd=;";
connect = new MySqlConnection(conn);
connect.Open();
}
catch (MySqlException e)
{
throw;
}
}
Add Reference Visual Studio.
Login Checker Codes
private bool checklogin(string user, string pass)
{
dbconnect();
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "Select * from accounts where username=@user and password=@pass";
cmd.Parameters.AddWithValue("@user", user);
cmd.Parameters.AddWithValue("@pass", pass);
cmd.Connection = connect;
MySqlDataReader login = cmd.ExecuteReader();
if (login.Read())
{
connect.Close();
return true;
}
else
{
connect.Close();
return false;
}
}
Variables
private string conn;
private MySqlConnection connect;
(Button Click Event)
private void button1_Click(object sender, EventArgs e)
{
string user = username.Text;
string pass = password.Text;
if (user == "" || pass == "")
{
MessageBox.Show("Empty Fields Detected ! Please fill up all the fields");
return;
}
bool r = checklogin(user, pass);
if (r)
MessageBox.Show("Correct Login Credentials");
else
MessageBox.Show("Incorrect Login Credentials");
}
Create Project and Design Form
Change Element Names,Using If Else and MessageBox Method with Button Click Event.
Testing Application
Making Close button.Using Application Exit Function with Button Click Event.
Change Textbox value type.I am using now passwordchar "*" character.
I hope it was helpful.
Posted on Utopian.io - Rewarding Open Source Contributors
interesting Good Luck
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Nice and Educative post! @odl
Hey @odl I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
This is amazing brother .. Id like to know how to create a programme .. from A to Z ...
Thank you bro keep goin'
It may be well advised to clarify "Windows' Operating System in Use" in your title for those who are allergic to it. ;)
I like it! Subscribe to your blog!