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
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
private OleDbConnection myconnection;
private OleDbCommand command;
private OleDbDataReader reader;
private string strcon, strrequet;// variable pour la connection et la command
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//regadre le form1_load c est le debut de programme
// ouvrire la connection
myconnection.Open();
// requete sql
//le % ca veux dir * quand je lui donne les 1er letre kay kemel men 3andou
strrequet = "select NomFoncier, NTF, Superficie, DateAchat, Prix, NatureFoncier, Lieu from client where num like'" + textBox1.Text + "%'";
command.CommandText = strrequet;
// j affecte le resultat de la command a un objet reader oledbreader
reader = command.ExecuteReader();
// tant que la lecture n est po fini je boucle pour afficher le resultat ds une listbox
while (reader.Read())
{
listBox1.Items.Add(reader["num"]);
}
myconnection.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
//la chaine de connection rien a comprendre hiya hakdak
strcon = @"Provider=Microsoft.Jet.OLEDB.4.0; data Source=c:\test.mdb";
myconnection = new OleDbConnection(strcon);
command = new OleDbCommand(strrequet, myconnection);
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
}
} |
Partager