Advertisement
moldovexc

theater_con

Nov 9th, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.OleDb;
  4. using System.Linq;
  5. using System.Security.Claims;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace theater
  10. {
  11.     internal class Connection
  12.     {
  13.         OleDbConnection connect;
  14.         OleDbCommand command;
  15.         private void connectionTo()
  16.         {
  17.             //connect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\TCP PROJECT\repairs.accdb");
  18.             connect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ShittyRestaurant\Documents\Theater.accdb");
  19.             command = connect.CreateCommand();
  20.         }
  21.         public Connection()
  22.         {
  23.             connectionTo();
  24.             //('1', '1', '1', 1, 1, 1, '1')";;
  25.  
  26.         }
  27.         public void insert(Theater theater)
  28.         {
  29.             try
  30.             {
  31.                 command.CommandText = "Insert into Theater([Staging], [Director], [Author], [Year], [Actor], [Actor_name], [Title], [Role], [Gender]) Values('" +
  32.                     theater.Staging + "','" + theater.Director + "','" + theater.Author + "','" + theater.Year + "','" + theater.Actor + "','" + theater.Actor_name + "','" + theater.Title + "','" + theater.Role + "','" + theater.Gender +
  33.                   "')";
  34.                 command.CommandType = System.Data.CommandType.Text;
  35.                 connect.Open();
  36.                 command.ExecuteNonQuery();
  37.             }
  38.             catch (Exception)
  39.             {
  40.                 System.Windows.Forms.MessageBox.Show("Incorrect data.");
  41.             }
  42.             finally
  43.             {
  44.                 if (connect != null)
  45.                 {
  46.                     connect.Close();
  47.                 }
  48.             }
  49.         }
  50.         public void updateCar(Theater theater)
  51.         {
  52.             try
  53.             {
  54.                 command.CommandText = "UPDATE Theater SET Staging = '" + theater.Staging + "', Director = '" + theater.Director + "', Author = '" + theater.Author +
  55.                   "', [Year] = '" + theater.Year + "', Actor = '" +theater.Actor + "', Actor_name = '" + theater.Actor_name + "', Title = '" + theater.Title + "', Role = '" + theater.Role + "', Gender = '" + theater.Gender + "' Where Theater_ID=" + theater.Theater_ID;
  56.                 // command.CommandText =  "UPDATE Car SET Reg_number = '" + car.Reg_number + "' WHERE Car_id = " + car.Car_id;
  57.                 command.CommandType = System.Data.CommandType.Text;
  58.                 connect.Open();
  59.                 command.ExecuteNonQuery();
  60.             }
  61.             catch (Exception)
  62.             {
  63.                 System.Windows.Forms.MessageBox.Show("Incorrect data.");
  64.             }
  65.             finally
  66.             {
  67.                 if (connect != null)
  68.                 {
  69.                     connect.Close();
  70.                 }
  71.             }
  72.  
  73.         }
  74.         public void deleteCar(Theater theater)
  75.         {
  76.  
  77.             try
  78.             {
  79.                 command.CommandText = "Delete  From Theater WHERE  Theater_ID=" + theater.Theater_ID;
  80.                 // command.CommandText =  "UPDATE Car SET Reg_number = '" + car.Reg_number + "' WHERE Car_id = " + car.Car_id;
  81.                 command.CommandType = System.Data.CommandType.Text;
  82.                 connect.Open();
  83.                 command.ExecuteNonQuery();
  84.             }
  85.             catch (Exception)
  86.             {
  87.                 System.Windows.Forms.MessageBox.Show("Incorrect data.");
  88.             }
  89.             finally
  90.             {
  91.                 if (connect != null)
  92.                 {
  93.                     connect.Close();
  94.                 }
  95.             }
  96.  
  97.         }
  98.     }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement