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
| '
Mon DGV est nommé ici
Je vide mon Dataset lors de chaque nouvelle requête..
ObjetDataSet.Clear()
'Convertion d'un string en nombre
Dim s As String = TextBox1.Text
Dim i As Integer
i = CInt(s) 'Transforme la chaine de caractère en integer
Dim strNom As String = TextBox2.Text
strNom = strNom.ToUpper
strConn = CStr("provider=microsoft.jet.oledb.4.0;" & "data source= " & Application.StartupPath & "\Gestions.mdb" & ";")
If RadioButton_Nom.Checked = True Then '===========recherche par Nom
strSql = "SELECT * FROM Clients where Nom= '" & strNom & "' order by Nom"
ElseIf RadioButton_Code.Checked = True Then '========recherche par code
strSql = "SELECT * FROM Clients where Code = " & i & " order by Prénom "
ElseIf RadioButton_Tous.Checked = True Then
strSql = "SELECT * FROM Clients order by Nom"
'Instanciation d'un Objet Connexion
End If
ObjetConnection = New OleDbConnection
'Donner à la propriété ConnectionString les paramètres de connexion
ObjetConnection.ConnectionString = strConn
'Ouvrir la connexion
ObjetConnection.Open()
'Instancier un objet Commande
ObjetCommand = New OleDbCommand(strSql)
'Instancier un objet Adapter
ObjetDataAdapter = New OleDbDataAdapter(ObjetCommand)
'initialiser l'objet Command
ObjetCommand.Connection() = ObjetConnection
'initialiser l'objet OleCBComandBuilder (sinon pas d'update)
ObjetCB = New OleDbCommandBuilder(ObjetDataAdapter)
'Avec l'aide de la propriété Fill du DataAdapter charger le DataSet
ObjetDataAdapter.Fill(ObjetDataSet, "Clients")
'Créer une datatable à partir du dataset
ObjetDataTable = ObjetDataSet.Tables("Clients")
'Mettre dans le DataGrid une table DataTable
DataGrid.DataSource = ObjetDataTable
DataGrid.Columns(0).Visible = False'je cache la 1 ère colonne
DataGrid.Columns(5).HeaderText = "Code postal"'je renomme le 5 ème colonne
TextBox1.Text = ""
TextBox2.Text = ""
Me.bindingSource = New BindingSource()
'met dans dans le bindingSource le dataset
bindingSource.DataSource = ObjetDataSet
'met la table
bindingSource.DataMember = "Clients"
'Adapte les controles au DataGrid
txtNom.DataBindings.Add("Text", bindingSource, "Nom", True, DataSourceUpdateMode.OnPropertyChanged)
txtPrénom.DataBindings.Add("Text", bindingSource, "Prénom", True, DataSourceUpdateMode.OnPropertyChanged) |
Partager