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
| Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Public Class Form1
'les variables
Dim Connection As New OleDbConnection
Dim DtSet As New DataSet()
Dim AdapTUSER As OleDbCommand
Dim marequete As String
Dim ole As OleDbCommand
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Matable As DataTable
DtSet.Tables.Clear()
'on parametre la chaine de connection pour la base de donnée testbdd.mdb
Connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\BDD_test.accdb;"
'on ouvre la connection
Connection.Open()
If Connection.State = ConnectionState.Open Then
Label1.Text = "connection ok"
End If
'ma requete
'sql = "select Mois, CU_h, RDV, Pourcentage_Production, Prime from R_Altitude_Prod where Matricule Like '%" & TextBox1.Text & "' And Annee Like '%" & TextBox2.Text & "' "
marequete = "select Mois, CU_h, RDV, Pourcentage_Production, Prime from R_Altitude_Prod where Matricule Like @param1 And Annee LIKE @param2"
With ole.Parameters
.Add(New OleDbParameter("@param1", SqlDbType.Int, 4))
.Add(New OleDbParameter("@param2", SqlDbType.Int, 4))
End With
'definition du DataAdapter
AdapTUSER = New OleDbCommand(marequete, Connection)
' rempli le dataset
AdapTUSER.Connection.Open()
AdapTUSER.ExecuteNonQuery()
AdapTUSER.Connection.Close
'on ferme la connection
Connection.Close()
'ajoute un datagrid sur ta form et ce code va relier ta table USER au datagrid qui va t'afficher les donnée
'affichage des données dans le datagrid
Matable = DtSet.Tables("R_Altitude_Prod")
With DataGrid1
'alimentation de matable
.DataSource = Matable
'Ligne paire en blanc
.RowsDefaultCellStyle.BackColor = Color.White
'ligne impaire en bleu claire
.AlternatingRowsDefaultCellStyle.BackColor = Color.LightBlue
'Empeche la saisie dans les cellules
.EditMode = DataGridViewEditMode.EditProgrammatically
'masquer l'entete de sélection
.RowHeadersVisible = False
End With
End Sub
End Class |
Partager