DDL(Data Definition Language) Create, Alter, Drop, Rename, Truncate queries perform in Database SQL

Create Login form by using select query

create login screen in c# using select query
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label4_Click(object sender, EventArgs e)
{
this.Hide();
Form2 fm2 = new Form2();
fm2.Show();

}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Password");
return;
}
bool iseq = false;
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
SqlCommand cmd = new SqlCommand(@"SELECT Email,Password FROM regtable", conn);
cmd.Parameters.AddWithValue("@email", textBox1.Text);
cmd.Parameters.AddWithValue("@password", textBox2.Text);
conn.Open();
SqlDataReader read = cmd.ExecuteReader();
while (read.Read())
{

//label3.Text = "Name is " + read["Email"].ToString();
string em = read["Email"].ToString();
string pswn = read["Password"].ToString();
if (textBox1.Text.Equals(em) && textBox2.Text.Equals(pswn))
{
iseq = true;

}

}
conn.Close();
if (iseq == true)
{
MessageBox.Show("Successfull Login");
this.Hide();
Form4 fm4 = new Form4();
fm4.Show();
}
else if(iseq == false)
{
MessageBox.Show("Invalid Login Details");

}



}

private void label6_Click(object sender, EventArgs e)
{

this.Hide();
Form3 fm3 = new Form3();
fm3.Show();
}
}
}

Create Registration form by using Insert query

create Registration form by using Insert query
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void label7_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}

private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter First Name");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Last Name");
return;
}
if (textBox3.Text == "")
{
MessageBox.Show("Please Enter City");
return;
}
if (textBox4.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox5.Text == "")
{
MessageBox.Show("Please Enter Password");
return;
}
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
SqlCommand cmd = new SqlCommand(@"INSERT INTO regtable (FirstName,LastName,City,Email,Password) VALUES (@firstname,@lastname,@city,@email,@password)", conn);
cmd.Parameters.Add("@firstname", textBox1.Text);
cmd.Parameters.Add("@lastname", textBox2.Text);
cmd.Parameters.Add("@city", textBox3.Text);
cmd.Parameters.Add("@email", textBox4.Text);
cmd.Parameters.Add("@password", textBox5.Text);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{

MessageBox.Show("Successfull Registered");
}
conn.Close();

}
}
}

Create forgot Password form by using update query

create forgot Password form by using update query in c sharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
MessageBox.Show("Please Enter Email");
return;
}
if (textBox4.Text == "")
{
MessageBox.Show("Please Enter City");
return;
}
if (textBox1.Text == "")
{
MessageBox.Show("Please Enter New Password");
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Please Enter Confirm Password");
return;
}
string email, city, password;
email = textBox3.Text;
city = textBox4.Text;
password = textBox2.Text;
if(textBox1.Text == password)
{
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string q = "update [regtable] set [Password]='" + password + "' where Email='" + email + "' and City='" + city + "'";
SqlCommand cmd = new SqlCommand(q, conn);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Password Successfully Changed");
}
else
{
MessageBox.Show("Sorry Your Details are Wrong");
}
conn.Close();
}
else
{
MessageBox.Show("Sorry your New Password and Confirm password is not Match");
}


}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();

}
}
}

Create Administrator form that can delete any record by using delete query

Create Administrator form that can delete any record by using delete query in c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab_14_create_register_database_login
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form1 fm1 = new Form1();
fm1.Show();
}

private void button1_Click(object sender, EventArgs e)
{
string email;
email = textBox1.Text;
SqlConnection conn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RegisterDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string q = "delete from regtable where Email='" + email + "'";
SqlCommand cmd = new SqlCommand(q, conn);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show($"{email} Record Seccessfully Deleted");
}
else
{
MessageBox.Show("Sorry Email Address is Wrong");
}
conn.Close();
}
}
}

Contact us - WSP Tech - World Solution Point Technologies

Contact Details for C# Projects

If you want any Project then contact our Customer support

Email: support@wsptech.pk

Mobile no: +92 304 5180559

You can contact any time on Mobile Number.

 

Leave a Comment

Your email address will not be published. Required fields are marked *