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
|
Dim strCon$ = CStr("provider=microsoft.jet.oledb.4.0;" & "data source= " & Application.StartupPath & "\Demandes.mdb" & ";")
Dim CnEnreg As New OleDb.OleDbConnection
Dim CmdR As New OleDb.OleDbCommand
Dim DtsetRecherche As New DataSet
Dim dtAdapteurRecherche As New OleDb.OleDbDataAdapter
CnEnreg.ConnectionString = strCon$
Dim requete As String
requete = "select Id_Piece as [No Piece]from Pieces where id_Piece like '%" & Me.Cbox_Pieces.Text & "%'"
CnEnreg.Open()
CmdR = CnEnreg.CreateCommand() 'Creation de commande
CmdR.CommandText = requete
' mode non connecté
DtsetRecherche = New DataSet
Try
' prepare le code pour afficher le resultat de la requete dans la datagridview
dtAdapteurRecherche = New OleDb.OleDbDataAdapter
dtAdapteurRecherche.SelectCommand = CmdR
dtAdapteurRecherche.Fill(DtsetRecherche, "Pieces")
MsgBox(DtsetRecherche.Tables.Item(0).Rows.Count)
If DtsetRecherche.Tables.Item(0).Rows.Count > 0 Then
Me.DG_Pieces.DataSource = DtsetRecherche.Tables("Pieces")
Me.DG_Pieces.Columns.Item(0).Visible = False
Me.DG_Pieces.Refresh()
End If
CnEnreg = Nothing
CmdR = Nothing
dtAdapteurRecherche = Nothing
'Objet déconnectée
DtsetRecherche = Nothing
Catch ex As OleDb.OleDbException
MsgBox(ex.Message)
CnEnreg = Nothing
CmdR = Nothing
dtAdapteurRecherche = Nothing
'Objet déconnectée
DtsetRecherche = Nothing
End Try
CnEnreg = Nothing
CmdR = Nothing
dtAdapteurRecherche = Nothing
'Objet déconnectée
DtsetRecherche = Nothing
Else
MsgBox("Veuillez choisir un critère dans la liste déroulante en-dessous du bouton de trie!", MsgBoxStyle.Information)
Cbox_Pieces.Focus()
End If |
Partager