daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 Exam18
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         MySqlConnection connection;
  17.         MySqlCommand command;
  18.         String connectionString = "server=localhost;" +
  19.                                     "database=mydb;" +
  20.                                     "user=root;" +
  21.                                     "password=524656bnm;";
  22.         String commandString;
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.             connection = new MySqlConnection();
  28.             connection.ConnectionString = connectionString;
  29.             command = new MySqlCommand();
  30.             command.Connection = connection;
  31.  
  32.             commandString = "select VacancyName, CompanyName from vacancy;";
  33.             command.CommandText = commandString;
  34.             connection.Open();
  35.             MySqlDataReader reader = command.ExecuteReader();
  36.  
  37.             while (reader.Read())
  38.             {
  39.                 comboBox1.Items.Add(reader[0].ToString() + "|" + reader[1].ToString());
  40.                
  41.             }
  42.             connection.Close();
  43.  
  44.         }
  45.  
  46.         private void Form1_Load(object sender, EventArgs e)
  47.         {
  48.  
  49.         }
  50.  
  51.         private void button2_Click(object sender, EventArgs e)
  52.         {
  53.             if (comboBox1.Text != "")
  54.             {
  55.                 String[] row;
  56.                 row = comboBox1.Text.Split('|');
  57.                 MessageBox.Show(row[0] + " " + row[1]);
  58.  
  59.                 commandString = "select expirience from vacancy where VacancyName=@vacname, CompanyName=@compname;";
  60.                 command.CommandText = commandString;
  61.                 command.Parameters.Add("@vacname", MySqlDbType.VarChar, 45).Value = row[0];
  62.                 command.Parameters.Add("@compname", MySqlDbType.VarChar, 100).Value = row[1];
  63.                 int exp;
  64.                 connection.Open();
  65.                 MySqlDataReader reader = command.ExecuteReader();
  66.                 exp = Convert.ToInt32(reader[1]);
  67.  
  68.                 command.Parameters.Clear();
  69.  
  70.  
  71.             }
  72.  
  73.         }
  74.  
  75.         private void button1_Click(object sender, EventArgs e)
  76.         {
  77.             commandString = "select u.Name, u.Surname, u.Pathronymic, s.institution, s.DateOfStartStud, s.DateOfEndStud, s.DateOfPlace, p.name, s.Experience " +
  78.                                 "from user u join  summary s on (s.nUserId = u.nID) " +
  79.                                 "join positions p on (p.nID = s.Positions_nID) where s.dateofplace between @date1 and @date2;";
  80.             command.CommandText = commandString;
  81.             command.Parameters.Add("@date1", MySqlDbType.Date).Value = dateTimePicker1.Value;
  82.             command.Parameters.Add("@date2", MySqlDbType.Date).Value = dateTimePicker2.Value;
  83.  
  84.             MySqlDataAdapter adapter = new MySqlDataAdapter(command);
  85.             DataTable dt = new DataTable();
  86.             adapter.Fill(dt);
  87.             dataGridView1.DataSource = dt;
  88.             connection.Close();
  89.             command.Parameters.Clear();
  90.         }
  91.     }
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top