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
| Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Public Class Form1
'déclaration de la conection, commande,datasource
Dim cs As String = "Data Source=C:\Users\DULAPLAST\Documents\Visual Studio 2008\Projects\GPAO DULAPLAST\GPAO DULAPLAST\Database1.sdf"
Dim con As SqlConnection = New SqlConnection(cs)
Dim command As SqlCommand = Nothing
Dim dr As SqlDataReader = Nothing
Public Sub connection()
con = New SqlConnection(cs)
command = New SqlCommand("SELECT référence FROM articles WHERE client= 'cli'", con)
' ouvre la connexion
con.Open()
dr = command.ExecuteReader()
End Sub
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
Dim cli As String
Me.TextBox4.Text = Me.ComboBox1.Text
cli = Me.ComboBox1.Text
' vide le ComboBox
Me.ComboBox2.Items.Clear()
Try
connection()
If dr.HasRows Then
' tant que le DataReader a une ligne d'enregistrements
While dr.Read
' ajouter la donnée au ComboBox
Me.ComboBox2.Items.Add(dr.GetValue(0))
End While
Else
MessageBox.Show("No result for your Data", "Infos", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not (dr Is Nothing) Then dr.Close()
If Not (con Is Nothing) Then con.Close()
End Try
End Sub |
Partager