1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
using capteur;
namespace test_bdd
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_MouseClick(object sender, MouseEventArgs e)
{
capt test = new capt();
// test.id_normal;
test.annee = 1995;
test.mois=1;
test.jour=2;
test.heure = 3;
test.minute=4;
test.seconde= 5;
test.temperature = 6;
test.humidite = 7;
test.vitesse_vent = 8;
test.direction_vent = 9;
test.vitesse_seve1 = 10;
test.vitesse_seve2 = 11;
string connStr = "server=localhost;user=root;database=bdd_seve;port=3306;password=;";
MySqlConnection conn = new MySqlConnection(connStr);
textBox1.Text = "Connecting to MySQL...";
conn.Open();
string sql = "INSERT INTO `bdd_seve`.`normal` (`id_normal`, `annee`, `mois`, `jour`, `heure`, `minute`, `seconde`, `temperature`, `humidite`, `vitesse_vent`, `direction_vent`, `vitesse_seve1`, `vitesse_seve2`) VALUES ('1', '" + test.annee.ToString() + "', '" + test.mois.ToString() + "', '" + test.jour.ToString() +"', '" + test.heure.ToString() +"', '" + test.minute.ToString() +"', '" + test.seconde.ToString() +"', '"+ test.temperature.ToString() +"', '" + test.humidite.ToString() +"', '" + test.vitesse_vent.ToString() +"', '" + test.direction_vent.ToString() +"', '" + test.vitesse_seve1.ToString() +"', '" + test.vitesse_seve2.ToString() +"')" ;
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
conn.Close();
conn.Open();
string sql1 = "SELECT annee,mois,jour FROM normal";
MySqlCommand cmd1 = new MySqlCommand(sql1, conn);
object result = cmd1.ExecuteScalar();
int r = Convert.ToInt32(result);
textBox1.Text = r.ToString();
//rdr.Close();
conn.Close();
//textBox1.Text = "Done.";
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
} |
Partager