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
|
Imports System.Data.OleDb
Public Class Form1
Dim MaConexion As New OleDbConnection
Dim MesDatas As New DataSet
Dim NomTablaEnDB As String
Dim MaComande As New OleDbCommand
Dim NomEtCheminDB As String = "D:\Tmp\AdminGouyette\contactslang.mdb" ' A changer selon le PC
Dim ChaineDeConnection As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & NomEtCheminDB & ";" ' Exécuter en x86
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Form2.Show()
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
MaConexion.Dispose()
MesDatas.Dispose()
MaComande.Dispose()
End Sub
Private Sub AfficheDetailHotesse(HotesseCherchee As String)
Try
MesDatas.Tables.Remove("DetailHotesse")
Catch ex As Exception
End Try
Dim UneTable As New DataTable
Dim PhraseSQL As String
'' Si "Hotesse" nécessaire dans le résultat
PhraseSQL = "SELECT Hotesse, Nom, Prénom, Adresse, CodePostal, Ville, telephone1 FROM contactlang WHERE Hotesse = '" & HotesseCherchee & "' ORDER BY Nom"
'' Si "Hotesse" PAS nécessaire dans le résultat
' PhraseSQL = "SELECT Nom, Prénom, Adresse, CodePostal, Ville, telephone1 FROM contactlang WHERE Hotesse = '" & HotesseCherchee & "' ORDER BY Nom"
MaConexion.ConnectionString = ChaineDeConnection
Dim MonAdapter As OleDbDataAdapter = New OleDbDataAdapter(PhraseSQL, MaConexion)
MonAdapter.Fill(UneTable)
UneTable.TableName = "DetailHotesse"
MesDatas.Tables.Add(UneTable)
MonAdapter.Dispose()
MaConexion.Close()
Try
Form2.DataGridView1.DataSource = Nothing
Form2.DataGridView1.Rows.Clear()
Catch ex As Exception
End Try
Form2.DataGridView1.DataSource = MesDatas.Tables("DetailHotesse")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
AfficheDetailHotesse(TextBox1.Text)
Catch
End Try
End Sub
End Class |
Partager