Login Form.................................................. using - TopicsExpress



          

Login Form.................................................. 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 WindowsFormsApplication3 { public partial class Form2 : Form { SqlConnection con; public Form2() { con = new SqlConnection("data source=SHYAM-PC;database=itsprk1;uid=sa;pwd=123456"); con.Open(); InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("select *from login where uid=@id or password=@pwd",con); cmd.Parameters.Add("@id", SqlDbType.VarChar).Value=textBox1.Text; cmd.Parameters.AddWithValue("@pwd",textBox2.Text); SqlDataReader dr=cmd.ExecuteReader(); string eid=""; string pwd=""; while (dr.Read()) { eid = dr[0].ToString(); pwd = dr[1].ToString(); } if (eid == textBox1.Text && pwd == textBox2.Text) { MessageBox.Show("Welcome"); } else { MessageBox.Show("unautorized user......"); } } } } .................................... New User 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 WindowsFormsApplication3 { public partial class Form3 : Form { SqlConnection con; public Form3() { con = new SqlConnection("data source=SHYAM-PC;database=itsprk1;uid=sa;pwd=123456"); con.Open(); InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand("insert into login values(@id,@name)",con); cmd.Parameters.AddWithValue("@id",textBox1.Text); cmd.Parameters.AddWithValue("@name",textBox2.Text); int x= cmd.ExecuteNonQuery(); if (x > 0) { MessageBox.Show("registr successfully"); Form2 f2 = new Form2(); this.Hide(); f2.ShowDialog(); } else { MessageBox.Show("error........."); } } private void Form3_Load(object sender, EventArgs e) { } } }
Posted on: Wed, 03 Jul 2013 08:51:49 +0000

Trending Topics



Recently Viewed Topics




© 2015