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();
}
}
}