can some one help by giving code for login

Recommended Answers

All 2 Replies

We are here to help you with code you have written, not write code for you. What have you written?

private void loginbtnbtn_Click(object sender, EventArgs e)
    {


            SqlConnection con = new SqlConnection();
            string str = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=cardb;Data Source=SAIDATTA-051EA8\\SQLEXPRESS";
            con.ConnectionString = str;
            con.Open();
            string query = "select  * from carlogin where empcode='" + textBox1.Text + "'";//textBox1=employeid
            SqlCommand cmd = new SqlCommand(query, con);

            SqlDataReader dr;

            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                string pwd = Convert.ToString(dr[1]);//textBox2=password


                if ((textBox2.Text == pwd) )
                {
                    MessageBox.Show("YOU ARE LOGGED IN AS ADMIN");
                    MDIParent2 m1 = new MDIParent2();// MDIParent2 is form for parent
                    m1.Show();



                }
                else if ((textBox2.Text == pwd) )
                {
                    MessageBox.Show("YOU ARE LOGGED IN AS AS STAFF");
                    MDIParent1 m = new MDIParent1();// MDIParent1 is form for staff
                    m.Show();


                }
                else
                {
                    MessageBox.Show(" invalid  username or password");

                }
            }
        }

table are in following formate

create table carlogin ( username varchar(40) canstraint primary key(username),password varchar(30) )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.