Soyez le premier à donner votre avis sur cette source.
Snippet vu 6 794 fois - Téléchargée 30 fois
Public strConnection as string="user id=sa;password=;initial catalog=NomBaseDeDonnées;server=ServeurBaseDeDonnées" Public Sub GetField(ByVal Ctrl As Object, ByVal strSQL As String) Dim DS As New DataSet() Try 'Recherche dans la base de données Dim DBCon As New SqlClient.SqlConnection(strConnection) Dim Query As New SqlClient.SqlDataAdapter(strSQL, DBCon) Query.Fill(DS) Query.Dispose() DBCon.Close() DBCon.Dispose() If DS.Tables(0).Rows.Count > 0 Then Dim C As Control 'Affiche les données suivants le control For Each C In Ctrl Select Case C.GetType.ToString Case "System.Windows.Forms.TextBox" Dim TB As TextBox = C If Not (TypeOf (DS.Tables(0).Rows(0).Item(TB.Name)) Is DBNull) Then TB.Text = DS.Tables(0).Rows(0).Item(TB.Name) Else TB.Text = "" End If Case "System.Windows.Forms.ComboBox" Dim CB As ComboBox = C If Not (TypeOf (DS.Tables(0).Rows(0).Item(CB.Name)) Is DBNull) Then Dim I As Integer If CB.Items.Count > 0 Then For I = 0 To CB.Items.Count - 1 If CB.Items(I).ToString.IndexOf(DS.Tables(0).Rows(0).Item(CB.Name), 0) <> -1 Then CB.SelectedIndex = I Next I End If End If Case "System.Windows.Forms.CheckBox" Dim CB As CheckBox = C If Not (TypeOf (DS.Tables(0).Rows(0).Item(CB.Name)) Is DBNull) Then If DS.Tables(0).Rows(0).Item(cb.Name) = True Then CB.Checked = True Else CB.Checked = False End If End If Case "System.Windows.Forms.ListBox" Dim LB As ListBox = C If Not (TypeOf (DS.Tables(0).Rows(0).Item(LB.Name)) Is DBNull) Then If LB.Items.Count > 0 Then Dim I As Integer For I = 0 To LB.Items.Count - 1 If LB.Items(I).ToString.IndexOf(DS.Tables(0).Rows(0).Item(LB.Name)) <> -1 Then LB.SelectedIndex = I End If Next I End If End If End Select GetField(C.Controls, strSQL) Next End If Catch Err As Exception MsgBox(Err.Message, MsgBoxStyle.Exclamation, "Erreur") Finally DS.Dispose() End Try End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e as System.EventArgs) Handles Button1.Click GetField(GroupBox1.Controls,"Select * From Employes Where EmployeId=1") End Sub
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.