Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 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.  
  13. namespace DB1
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         MySqlConnection cm;
  18.         int i = 0;
  19.         DateTime dateValue;
  20.         //string MySQLFormatDate = dateValue.ToString("yyyy-MM-dd");
  21.  
  22.  
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.         private void Form1_Load(object sender, EventArgs e)
  29.         {
  30.             try
  31.             {
  32.                
  33.                 cm = new MySqlConnection();
  34.                 cm.ConnectionString = "server=127.0.0.1;uid=neuro;pwd=123;database=neuro;";
  35.                 cm.Open();
  36.                 MessageBox.Show("Connected to the DataBase");
  37.             }
  38.             catch (MySql.Data.MySqlClient.MySqlException ex)
  39.             {
  40.                 MessageBox.Show(ex.Message);
  41.             }
  42.         }
  43.         //adicionar dados
  44.         private void button1_Click(object sender, EventArgs e)
  45.         {
  46.            
  47.             MySqlCommand cmd = new MySqlCommand();
  48.             //cmd.CommandText = "INSERT INTO testes (data,nota) VALUES (@data,@nota)";
  49.            cmd.CommandText = "UPDATE testes SET data = " + data.Text + " WHERE disciplina='" + disciplina.Text + "'" ;
  50.             cmd.CommandType = CommandType.Text;
  51.                     cmd.Connection = cm;
  52.             //  " DELETE FROM `testes` WHERE `testes`.`id` = 12"?
  53.            
  54.             //cmd.Parameters.AddWithValue("@data", data.Text);
  55.               //      cmd.Parameters.AddWithValue("@nota", notas.Text);
  56.                     cmd.ExecuteNonQuery();
  57.         }
  58.  
  59.         //recolher dados
  60.         private void button2_Click(object sender, EventArgs e)
  61.         {
  62.            
  63.            
  64.             MySqlCommand cmd = new MySqlCommand();
  65.             cmd.CommandText = "SELECT disciplina, nota, data FROM testes";// WHERE nota = 20
  66.             cmd.CommandType = CommandType.Text;
  67.             cmd.Connection = cm;
  68.             MySqlDataReader rdr = cmd.ExecuteReader();
  69.             while (rdr.Read())
  70.             {
  71.  
  72.                 dataGridView1.Rows.Add();
  73.                 dataGridView1.Rows[i].Cells[0].Value = rdr[0];
  74.                 dataGridView1.Rows[i].Cells[1].Value = rdr[1];
  75.  
  76.              
  77.                 i += i + 1;
  78.             }
  79.             rdr.Close();
  80.  
  81.  
  82.         }
  83.  
  84.  
  85.         //updates na tabela
  86.         private void button3_Click(object sender, EventArgs e)
  87.         {
  88.             MySqlCommand cmd = new MySqlCommand();
  89.             cmd.CommandText = "UPDATE testes SET disciplina='Ingles' WHERE disciplina='Portugues'";
  90.             cmd.CommandType = CommandType.Text;
  91.             cmd.Connection = cm;
  92.             cmd.ExecuteNonQuery();
  93.         }
  94.  
  95.         private void data_TextChanged(object sender, EventArgs e)
  96.         {
  97.  
  98.         }
  99.  
  100.         private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  101.         {
  102.             dateValue.ToString;
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement