ListBox
اود في عرض اسماء الموظفين في الست بوكس بمجرد اختيار اسم القسم من الدروب دون لست
عملت الكود ولكن مو راضي يعرض الاسماء ياليت تساعدوني في حل المشكلة
هناك جدولين :
1- Employee (Empl_No , Empl_name,Dept_no )
2- Department ( Dept_no,Dept_name )
المفتاح الرئيسي في جدول الاقسام هو Dept_no
المفتاح الرئيسي في جدول الموظفين هو Empl_no
الكود :
Private Sub ddls_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddls.SelectedIndexChanged
Dim selecsql As String = "select * from department,Employee where department.dept_no=Employee.dept_no and Employee.dept_no = ' " & ddls.SelectedItem.Value & " '"
Dim conn As New SqlConnection(costring)
Dim cm As New SqlCommand(selecsql, conn)
Dim dr As SqlDataReader
Try
conn.Open()
dr = cm.ExecuteReader()
ListBox1.DataSource = dr
ListBox1.DataTextField = "empl_name"
ListBox1.DataValueField = "empl_no"
ListBox1.DataBind()
Catch ex As Exception
Lblfo.Text = "Error Reading Department err.message"
Finally
If (Not conn Is Nothing) Then
conn.Close()
End If
End Try
End Sub