Create Login Window in C# Step by step Using Sql Server - PROJECT & TECHNICAL

Thursday, November 1, 2018

Create Login Window in C# Step by step Using Sql Server





++CODE++ using System.Windows.Forms; using System.Data.SqlClient; namespace proj { public partial class Form1: Form { SqlConnection gObjConn; SqlCommand gObjcmd; SqlDataAdapter gObjAdpt; DataSet gObjDs; string gsSqlQuery = ""; string gsConnStr = ""; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { gsConnStr = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=reg;Data Source=AVINASH\SQLEXPRESS"; } private void button1_Click(object sender, EventArgs e) { gObjConn = new SqlConnection(gsConnStr); gObjConn.Open(); gsSqlQuery = "Select UserName from Login_user where UserName='" + textBox1.Text + "' and Password='" + textBox2.Text + "'"; gObjcmd = new SqlCommand(gsSqlQuery, gObjConn); gObjcmd.ExecuteNonQuery(); gObjAdpt = new SqlDataAdapter(gObjcmd); gObjDs = new DataSet(); gObjAdpt.Fill(gObjDs); if (gObjDs.Tables[0].Rows.Count (grather than sign use)0) { MessageBox.Show("Valid username or password"); } else { MessageBox.Show("Invalid username or password"); } } } }

website: https://avinashit.com/

1 comment: