C# Windows Login Form With SQL Server
Introduction :
This artical Explain how to Login in windows form using SQL Server Database with C#.
Step 1 : Create Windows Form Project
Step 2 : Create Databse
Step 3 : Create Class DAL.cs
   public class DAL
{
public int id { get; set; }
public string uname { get; set; }
public string pwd { get; set; }
}
{
public int id { get; set; }
public string uname { get; set; }
public string pwd { get; set; }
}
Step 4 :  Create Class BAL.cs
  public class BAL
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=
D:\program\Windows_Login\Database1.mdf;Integrated Security=True;User Instance=True");
public DataTable Login_data(DAL da)
{
DataTable dt = new DataTable();
         
SqlDataAdapter adp = new SqlDataAdapter("select * from Login_master where
name='"+da.uname+"' and password='"+da.pwd+"'",con);
adp.Fill(dt);
return dt;
}
}
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=
D:\program\Windows_Login\Database1.mdf;Integrated Security=True;User Instance=True");
public DataTable Login_data(DAL da)
{
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter("select * from Login_master where
name='"+da.uname+"' and password='"+da.pwd+"'",con);
adp.Fill(dt);
return dt;
}
}
step 5 : Add Windows Form
step 6 : Form1.cs
 public partial class Form1 : Form
    {
        DAL da = new DAL();
        BAL ba = new BAL();
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
           DataTable dt=new DataTable();
            da.uname=txt_user.Text;
            da.pwd=txt_pwd.Text;
            dt = ba.Login_data(da);
            if (dt.Rows.Count > 0)
            {
                Home h1 = new Home();
                h1.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Invalid User and password ??????");
            }
 }step 7 :    Run Programe :
Login Successfully
See Other Tutorial :
* AngularJS With ASP.NET MVC
* Convert Rows to columns using 'Pivot' in SQL Server
* Mvc Registration page With user exist using Ajax method
* MVC 4 How to Perform Insert Update Delete Edit Select Operation
* MVC4 Edit,update,Delete,cancel inside gridview using sql database
* MVC 4 Gridview To Display Data Using SQL Server Database With Simple code
* Login page in asp.net Mvc4 Web application
* Mvc4 How to bind Dropdown List using Sql Database
* Gridview find control in asp.net
Sign up here with your email
 




1 comments:
Write commentschetu patel आज आप ने जो जानकारी दी है वो बहुत ही अछि दी है ये पोस्ट बिलकुल वर्क कर रही है ॰
Replyधन्यवाद
from : http://computerhindiknowledge.blogspot.in
ConversionConversion EmoticonEmoticon