Wednesday, May 11, 2016

C# login page using ADO.Net

Firstly create table in the database by name login 

C# code :-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
 
namespace WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SqlDataAdapter da;
        DataSet ds;
 
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("select * from login", "data source=MKS-PC\\SQLEXPRESS;Initial Catalog=master;integrated security=true");
            ds = new DataSet();
            da.Fill(ds);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr[0].ToString().Trim() == textBox1.Text && dr[1].ToString().Trim() == textBox2.Text)
                {
                    Form2 f = new Form2();
                    f.Show();
 
                    break;
 
                }
 
                else
                {
                    MessageBox.Show("Invalid");
                }
 
            }
        }
    }
}

Output : 


No comments:

Post a Comment