Private Sub cboDep1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDep1.SelectedValueChanged
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_dep2")
sb.Append(" WHERE dep1ID ='" & cboDep1.SelectedValue.ToString & "'")
Dim sqlIni As String
sqlIni = sb.ToString()
If isFind2 = True Then
ds.Tables("tbl_dep2").Clear()
End If
da = New SqlDataAdapter(sqlIni, Conn)
da.Fill(ds, "tbl_dep2")
With cboDep2
.DataSource = ds.Tables("tbl_dep2")
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
End With
isFind2 = True
iDep1.SelectedValue = cboDep1.SelectedValue
End Sub
Private Sub frmPeople_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblPeopleID.BackColor = Color.FromArgb(0, 0, 0, 0)
Dim FD As New FormFader
FD.FadeIn(Me, 0.25)
sw.Reset()
sw.Start()
Dim strConn As String
strConn = DBConnString.strConn
Conn = New SqlConnection()
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
sb = New StringBuilder()
sb.Append("SELECT * FROM tbl_preT;")
sb.Append("SELECT * FROM tbl_preE;")
sb.Append("SELECT * FROM tbl_type;")
sb.Append("SELECT * FROM tbl_campus;")
sb.Append("SELECT * FROM tbl_dep1 ORDER BY dep1Name;")
sb.Append("SELECT * FROM tbl_dep2 ORDER BY dep2Name;")
Dim sqlIni As String
sqlIni = sb.ToString()
RemoveHandler cboPreT.SelectedValueChanged, AddressOf cboPreT_SelectedValueChanged
RemoveHandler cboPreE.SelectedValueChanged, AddressOf cboPreE_SelectedValueChanged
RemoveHandler cboCampus.SelectedValueChanged, AddressOf cboCampus_SelectedValueChanged
RemoveHandler cboDep1.SelectedValueChanged, AddressOf cboDep1_SelectedValueChanged
RemoveHandler cboDep2.SelectedValueChanged, AddressOf cboDep2_SelectedValueChanged
RemoveHandler cboType.SelectedValueChanged, AddressOf cboType_SelectedValueChanged
com = New SqlCommand()
With com
.CommandText = sqlIni
.CommandType = CommandType.Text
.Connection = Conn
dr = .ExecuteReader()
If dr.HasRows Then
dtPreT = New DataTable
dtPreT.Load(dr)
With cboPreT
.BeginUpdate()
.DisplayMember = "preTNameS"
.ValueMember = "preTID"
.DataSource = dtPreT
.EndUpdate()
End With
dtPreE = New DataTable
dtPreE.Load(dr)
With cboPreE
.BeginUpdate()
.DisplayMember = "preENameS"
.ValueMember = "preEID"
.DataSource = dtPreE
.EndUpdate()
End With
dtType = New DataTable
dtType.Load(dr)
With cboType
.BeginUpdate()
.DisplayMember = "typeName"
.ValueMember = "typeID"
.DataSource = dtType
.EndUpdate()
End With
dtCampus = New DataTable
dtCampus.Load(dr)
With cboCampus
.BeginUpdate()
.DisplayMember = "CampusNameS"
.ValueMember = "campusID"
.DataSource = dtCampus
.EndUpdate()
End With
dtDep1 = New DataTable
dtDep1.Load(dr)
da = New SqlDataAdapter(sqlIni, Conn)
' da.Fill(ds, "tbl_dep1")
With cboDep1
.BeginUpdate()
.DisplayMember = "dep1Name"
.ValueMember = "dep1ID"
.DataSource = dtDep1
.EndUpdate()
End With
dtDep2 = New DataTable
dtDep2.Load(dr)
With cboDep2
.BeginUpdate()
.DisplayMember = "dep2Name"
.ValueMember = "dep2ID"
.DataSource = dtDep2
'.DataSource = ds.Tables("tbl_dep1")
.EndUpdate()
End With
End If
End With
dr.Close()
Tag : .NET, Ms SQL Server 2005, VB.NET, VS 2005 (.NET 2.x)