Advertisement
Nithisaran

Untitled

Nov 7th, 2020
2,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace RERU
  13. {
  14.     public partial class Form4 : Form
  15.     {
  16.         public Form4()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         public static string connectorString = "server = localhost;Database=reru;User ID=root;Password=";
  22.  
  23.         private void Form4_Load(object sender, EventArgs e)
  24.         {
  25.             this.TopMost = true;
  26.         }
  27.  
  28.         private void button1_Click(object sender, EventArgs e)
  29.         {
  30.  
  31.             string query = $"INSERT INTO act (act.act_Name,act.act_Date,act.act_Exp,act.act_Type,act.act_Term,act.act_Year) VALUES ('{textBox1.Text}','{dateTimePicker1.Text}','{dateTimePicker2.Text}','{comboBox1.Text}','{comboBox2.Text}/{maskedTextBox1.Text}','{checkedListBox1.Text}')";
  32.             MessageBox.Show(query);
  33.             MySqlConnection Conn = new MySqlConnection(connectorString);
  34.             //this.Hide();
  35.             //(new Form2()).Show();
  36.             try
  37.             {
  38.                 Conn.Open();
  39.                 MySqlCommand myCommand = new MySqlCommand(query, Conn);
  40.                 myCommand.ExecuteNonQuery();
  41.                 MessageBox.Show("Added");
  42.                 Conn.Close();
  43.             }
  44.             catch(Exception ex)
  45.             {
  46.                 MessageBox.Show(ex.Message);
  47.             }
  48.         }
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement