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 WindowsFormsApplication24 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string msg; SqlConnection con = new SqlConnection("Data Source=ITC-002;Initial Catalog=Tempabc;User ID=sa;Password=********"); SqlCommand cmd; DataSet ds = new DataSet(); private void btn_login_Click(object sender, EventArgs e) { try { if (txtbx_name.Text == "" || txtbox_password.Text == "") { MessageBox.Show(" Enter UserName and Password ."); return; } cmd = new SqlCommand("SELECT * FROM LoginDetails where Name='" + txtbx_name.Text + "' and Password='" + txtbox_password.Text + "'", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); int i = ds.Tables[0].Rows.Count; if (i == 1) { msg = "Welcome " + txtbx_name.Text; this.Hide(); Form2 f2 = new Form2(msg); f2.Show(); ds.Clear(); } else { MessageBox.Show("Not Registered User or Invalid Name/Password"); txtbox_password.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btn_register_Click(object sender, EventArgs e) { try { if (txtbx_name.Text == "" || txtbox_password.Text == "") { MessageBox.Show(" Enter UserName and Password ."); return; } /** checking whether name exists **/ cmd = new SqlCommand("SELECT * FROM LoginDETAILS where Name='" + txtbx_name.Text + "'", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); //filling dataset int i = ds.Tables[0].Rows.Count; //checking rows count in dataset if (i > 0) { MessageBox.Show("UserName " + txtbx_name.Text + " Already Exists.."); txtbox_password.Text = ""; ds.Clear(); //clearing dataset } else { /** inserting name and password in table logindetails **/ cmd = new SqlCommand("INSERT INTO LOGINDETAILS VALUES('" + txtbx_name.Text + "','" + txtbox_password.Text + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); msg = "Registered Successfully \n Welcome " + txtbx_name.Text; this.Hide(); //hiding form1 Form2 f2 = new Form2(msg); f2.Show(); //showing form2 } } catch (Exception ex) { MessageBox.Show(ex.Message); con.Close(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)