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 86 87 88 89
|
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 System.Data.SQLite;
using System.IO;
using System.Data.Common;
namespace WindowsFormsApplication1
{
public partial class Cheval : Form
{
public Cheval()
{
InitializeComponent();
CenterToScreen();
}
private void Cheval_Load(object sender, EventArgs e)
{
}
private void button_Annuler_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_enregistrer_Click(object sender, EventArgs e)
{
if (!File.Exists("test2.s3db"))
{
SQLiteConnection.CreateFile("test2.s3db");
using (DbConnection cnn = new SQLiteConnection("Data Source=test2.s3db"))
{
cnn.Open();
DbTransaction trans = cnn.BeginTransaction();
DbCommand cmm = cnn.CreateCommand();
cmm.Transaction = trans;
cmm.CommandText = "CREATE TABLE T_Attelage(Id_CA INT NOT NULL PRIMARY KEY, Lieu TEXT NOT NULL, Date DATE NOT NULL, Categorie TEXT NOT NULL, Championnat TEXT NULL, Nr_Epreuve TEXT NOT NULL, Ecuries TEXT NULL, PrixEcuries INT NULL, Montant INT NULL, Remarques TEXT NULL, Propositions TEXT NULL, SiteWeb TEXT NULL, LimiteInscription DATE NOT NULL);";
cmm.ExecuteNonQuery();
cmm = cnn.CreateCommand();
cmm.CommandText = "INSERT INTO T_Attelage Values(@Id_CA, @Lieu, @Date, @Categorie, @Championnat, @Nr_Epreuve, @Ecuries, @PrixEcuries, @Montant, @Remarques, @Propositions, @SiteWeb, @LimiteInscription);";
cmm.Parameters.AddRange(new SQLiteParameter[13] { new SQLiteParameter("@Id_CA"), new SQLiteParameter("@Lieu"), new SQLiteParameter("@Date"), new SQLiteParameter("@Categorie"), new SQLiteParameter("@Championnat"), new SQLiteParameter("@Nr_Epreuve"), new SQLiteParameter("@Ecuries"), new SQLiteParameter("@PrixEcuries"), new SQLiteParameter("@Montant"), new SQLiteParameter("@Remarques"), new SQLiteParameter("@Propositions"), new SQLiteParameter("@SiteWeb"), new SQLiteParameter("@LimiteInscription ") });
for (int Id_CA = 0; Id_CA < 10; Id_CA++)
{
cmm.Parameters[0].Value = Id_CA;
cmm.Parameters[1].Value = "Neuchâtel" ;
cmm.Parameters[2].Value = "30.04.2008" ;
cmm.Parameters[3].Value = "RI" ;
cmm.Parameters[4].Value = "ZKV" ;
cmm.Parameters[5].Value = "4" ;
cmm.Parameters[6].Value = "non" ;
cmm.Parameters[7].Value = "0" ;
cmm.Parameters[8].Value = "50" ;
cmm.Parameters[9].Value = "Essai" ;
cmm.Parameters[10].Value = "www.google.ch" ;
cmm.Parameters[11].Value = "www.google.ch";
cmm.Parameters[12].Value = "15.03.2008" ;
cmm.ExecuteNonQuery();
}
trans.Commit();
}
}
using (DbConnection cnn = new SQLiteConnection("Data Source=test2.s3db"))
{
cnn.Open();
DbCommand cmm = cnn.CreateCommand();
cmm.CommandText = "SELECT * FROM T_Attelage where Id_CA=@Id_CA;";
cmm.Parameters.Add(new SQLiteParameter("@Id_CA", "5"));
DataTable dt = new DataTable();
dt.Load(cmm.ExecuteReader());
}
}
}
} |
Partager