Hey This can help use

It's a simple Code




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Credential

partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text == "") && (textBox2.Text == ""))
                {
                    MessageBox.Show("Please enter details");
                }
            else
            {
            SqlConnection con = new SqlConnection();

            //con.ConnectionString = "server=;database=;Integrated
Security=true";
                con.Open();
            SqlCommand cmd = new SqlCommand("select * from login where id='"
+ textBox1.Text + "'", con);
            SqlDataReader dr = cmd.ExecuteReader();
            string st = "";
            string st1 = "";
            while (dr.Read())
            {
                st=dr[0].ToString();
                st1=dr[1].ToString();
            }
            if (textBox1.Text == st && textBox2.Text == st1)
            {

                Home hm = new Home();
                hm.Show();

                this.Close();



            }
            else


                {
                    MessageBox.Show("Wrong UserId or Password");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }


                                   }



}



This is a siple code Which Checks the values from Sql server Database

Reply via email to