Private Sub CBSEC2_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBSEC2.SelectedValueChanged
Dim sql As String = ""
If CBSEC2.SelectedValue = "SEC-01" Then
sql = "select From Employee where Section_Id = 'SEC-01'"
ElseIf CBSEC2.SelectedValue = "SEC-02" Then
sql = "select From Employee where Section_Id = 'SEC-02' "
ElseIf CBSEC2.SelectedValue = "SEC-03" Then
sql = "select From Employee where Section_Id = 'SEC-03' "
ElseIf CBSEC2.SelectedValue = "SEC-04" Then
sql = "select From Employee where Section_Id = 'SEC-04' "
End If
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
'Dim s44 As String = " select *from Employee"
Dim da3 As New SqlDataAdapter(sql, cn)
Dim ds3 As New DataSet
da3.Fill(ds3, "Emp")
With CBEMP
.DisplayMember = "Emp_Name"
.ValueMember = "Emp_Id"
.DataSource = ds3.Tables("Emp")
End With
cn.Close()
End Sub
ขาด * ครับ SELECT * FROM Employee WHERE Section_Id=......
ทำไมไม่ใช้แบบนี้ไม่เลยละครับ SELECT * FROM Employee WHERE Section_Id='" & CBSEC2.SelectedValue & "'
ไม่ต้องใช้ IF ELSE ก็ได้
Date :
2012-01-23 21:01:33
By :
Nameless
No. 2
Guest
Code (VB.NET)
Private Sub CBSEC2_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBSEC2.SelectedValueChanged
Dim sql As String = ""
sql = "SELECT * FROM Employee WHERE Section_Id = SEC-01 " & CBSEC2.SelectedValue & "'"
sql = "SELECT * FROM Employee WHERE Section_Id = 'SEC-02'" & CBSEC2.SelectedValue & "'"
sql = "SELECT * FROM Employee WHERE Section_Id = 'SEC-03'" & CBSEC2.SelectedValue & "'"
sql = "SELECT * FROM Employee WHERE Section_Id = 'SEC-04'" & CBSEC2.SelectedValue & "'"
End Sub