In this blog post I'll tell you how to create a Login window using C# programming language in Visual Studio 2012. Simply watch the video below and you'll get to know how to program a login window and how to make it work using SQL database server.
here is the final view of the login window
watch the video below:
here is the final view of the login window
watch the video below:
Here is the code that I've used in this project
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace LoginForm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void button2_Click(object sender, EventArgs e) { SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename='D:\C sharp\Projects\LoginForm\LoginForm\Data.mdf';Integrated Security=True;Connect Timeout=30;"); SqlDataAdapter sqlDataAdapt = new SqlDataAdapter("Select Count(*) From Login where Username='" + textBox1.Text + "' and Password ='" + textBox2.Text + "'", sqlcon); DataTable dt= new DataTable(); sqlDataAdapt.Fill(dt); if (dt.Rows[0][0].ToString() == "1") { this.Hide(); Main form = new Main(); form.Show(); } else { MessageBox.Show("Please Check Your Username & Password!"); } } private void textBox2_TextChanged(object sender, EventArgs e) { } } } |
If you have any questions, feel free to comment them down in the comment section. and do share this tutorial with you friends and like our facebook page
appreciate your work !
ReplyDeleteThank you very much! Keep in touch with us! subscribe my youtube channel, like my page and share. That'll be a huge encouragement to me.
Delete