06-11-15, 10:53 PM
الكود لكل الفورم
شغال 100%
كود :
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As New SqlConnection
Dim comm As SqlCommand = New SqlCommand
Dim reader As SqlDataReader
Dim dt As New DataTable
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Private Sub dailyreportentryform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con = New SqlConnection
con.ConnectionString = "your string"
con.Open()
fillcombo1()
fillcombo2()
MsgBox("تم الاتصال بنجاح", MsgBoxStyle.Information)
End Sub
'لتعبئة الكمبوبوكس الأول
Private Sub fillcombo1()
ds = New DataSet
da = New SqlDataAdapter(" select * from Countries", con)
da.Fill(ds, "Countries")
ComboBox1.DataSource = ds.Tables("Countries")
ComboBox1.ValueMember = "CountryID"
ComboBox1.DisplayMember = "CountryName"
End Sub
'لتعبئة الكمبوبوكس الثاني
Private Sub fillcombo2()
ds = New DataSet
da = New SqlDataAdapter(" select * from Cities where CountryID='" & ComboBox1.SelectedValue.ToString & "'", con)
da.Fill(ds, "Cities")
ComboBox2.DataSource = ds.Tables("Cities")
ComboBox2.ValueMember = "CityID"
ComboBox2.DisplayMember = "CityName"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If sender.focused = False Then Exit Sub
fillcombo2()
End Sub
End Classشغال 100%
