Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace DB1
- {
- public partial class Form1 : Form
- {
- MySqlConnection cm;
- int i = 0;
- DateTime dateValue;
- //string MySQLFormatDate = dateValue.ToString("yyyy-MM-dd");
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- try
- {
- cm = new MySqlConnection();
- cm.ConnectionString = "server=127.0.0.1;uid=neuro;pwd=123;database=neuro;";
- cm.Open();
- MessageBox.Show("Connected to the DataBase");
- }
- catch (MySql.Data.MySqlClient.MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- //adicionar dados
- private void button1_Click(object sender, EventArgs e)
- {
- MySqlCommand cmd = new MySqlCommand();
- //cmd.CommandText = "INSERT INTO testes (data,nota) VALUES (@data,@nota)";
- cmd.CommandText = "UPDATE testes SET data = " + data.Text + " WHERE disciplina='" + disciplina.Text + "'" ;
- cmd.CommandType = CommandType.Text;
- cmd.Connection = cm;
- // " DELETE FROM `testes` WHERE `testes`.`id` = 12"?
- //cmd.Parameters.AddWithValue("@data", data.Text);
- // cmd.Parameters.AddWithValue("@nota", notas.Text);
- cmd.ExecuteNonQuery();
- }
- //recolher dados
- private void button2_Click(object sender, EventArgs e)
- {
- MySqlCommand cmd = new MySqlCommand();
- cmd.CommandText = "SELECT disciplina, nota, data FROM testes";// WHERE nota = 20
- cmd.CommandType = CommandType.Text;
- cmd.Connection = cm;
- MySqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- dataGridView1.Rows.Add();
- dataGridView1.Rows[i].Cells[0].Value = rdr[0];
- dataGridView1.Rows[i].Cells[1].Value = rdr[1];
- i += i + 1;
- }
- rdr.Close();
- }
- //updates na tabela
- private void button3_Click(object sender, EventArgs e)
- {
- MySqlCommand cmd = new MySqlCommand();
- cmd.CommandText = "UPDATE testes SET disciplina='Ingles' WHERE disciplina='Portugues'";
- cmd.CommandType = CommandType.Text;
- cmd.Connection = cm;
- cmd.ExecuteNonQuery();
- }
- private void data_TextChanged(object sender, EventArgs e)
- {
- }
- private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
- {
- dateValue.ToString;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement