Advertisement
AleksandarH

C#/SQL 2

Nov 9th, 2022
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. using System.Drawing;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Data.SqlClient;
  6.  
  7. namespace ChainOfStores
  8. {
  9.     public partial class Form1 : Form
  10.     {
  11.         public Form1()
  12.         {
  13.             InitializeComponent();
  14.         }
  15.  
  16.         private void Insert_Click(object sender, EventArgs e)
  17.         {
  18.             SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\mihai\\source\\repos\\ChainOfStores\\ChainOfStores\\Database1.mdf;Integrated Security=True");
  19.             con.Open();
  20.             SqlCommand cmd = new SqlCommand("INSERT INTO Store VALUES (@Company,@FullName,@Address,@Manufacturer,@Invested,@Shareholding,@Number,@Registration)", con);
  21.             cmd.Parameters.AddWithValue("@Company", Company.Text);
  22.             cmd.Parameters.AddWithValue("@FullName", fullName.Text);
  23.             cmd.Parameters.AddWithValue("@Address", Address.Text);
  24.             cmd.Parameters.AddWithValue("@Manufacturer", Manufacturer.Text);
  25.             cmd.Parameters.AddWithValue("@Invested", Invested.Text);
  26.             cmd.Parameters.AddWithValue("@Shareholding", Shareholding.Text);
  27.             cmd.Parameters.AddWithValue("@Number", Number.Text);
  28.             cmd.Parameters.AddWithValue("@Registration", Registration.Text);
  29.             cmd.ExecuteNonQuery();
  30.             con.Close();
  31.             MessageBox.Show("Added Successfully!","",MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  32.         }
  33.  
  34.         private void Edit_Click(object sender, EventArgs e)
  35.         {
  36.             SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\mihai\\source\\repos\\ChainOfStores\\ChainOfStores\\Database1.mdf;Integrated Security=True");
  37.             con.Open();
  38.             SqlCommand cmd = new SqlCommand("Update Store set Company=@Company",con);
  39.             cmd.Parameters.AddWithValue("@Company", Company.Text);
  40.             cmd.ExecuteNonQuery();
  41.             con.Close();
  42.             MessageBox.Show("Edited Successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  43.         }
  44.  
  45.         private void Remove_Click(object sender, EventArgs e)
  46.         {
  47.             SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\mihai\\source\\repos\\ChainOfStores\\ChainOfStores\\Database1.mdf;Integrated Security=True");
  48.             con.Open();
  49.             SqlCommand cmd = new SqlCommand("DELETE FROM Store WHERE Company=@Company",con);
  50.             cmd.Parameters.AddWithValue("@Company", Company.Text);
  51.             cmd.ExecuteNonQuery();
  52.             con.Close();
  53.             MessageBox.Show("Removed Successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement