Imports system.data.oledb
Public Class nwindnet1
Dim strdb As String = "c:\northwind.mdb"
Dim strconn As String = "provider=microsoft.jet.oledb.4.0;data source=" & strdb
Dim strsql As String
Dim cn As New System.Data.OleDb.OleDbConnection(strconn)
Dim cm As New OleDbCommand(strsql, cn)
Dim dr As OleDbDataReader
Private Sub nwindnet1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
read_mdb()
End Sub
Sub read_mdb()
ListBox1.Items.Clear()
strsql = "select categoryid,categoryname from categories"
cm = New OleDbCommand(strsql, cn)
cn.Open()
dr = cm.ExecuteReader()
While dr.Read()
ListBox1.Items.Add(dr.Item("categoryid") & "," & dr.Item(1))
End While
cn.Close()
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ComboBox1.Items.Clear()
strsql = "select * from products where categoryid=" & Split(ListBox1.Text, ",")(0)
cm = New OleDbCommand(strsql, cn)
cn.Open()
dr = cm.ExecuteReader()
While dr.Read()
ComboBox1.Items.Add(dr.Item(0) & "," & dr.Item(1))
End While
cn.Close()
ComboBox1.Select()
ComboBox1.Text = ComboBox1.Items.Item(0)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Items.Clear()
strsql = "select * from [order details] "
strsql &= "where productid = " & Split(ComboBox1.Text, ",")(0)
cm = New OleDbCommand(strsql, cn)
cn.Open()
dr = cm.ExecuteReader()
While dr.Read()
ComboBox2.Items.Add(dr.Item(0) &","& dr.Item(1) &","& dr.Item(3))
End While
cn.Close()
ComboBox2.Select()
ComboBox2.Text = ComboBox2.Items.Item(0)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
ComboBox3.Items.Clear()
strsql = "select * from [orders] "
strsql &= "where orderid = " & Split(ComboBox2.Text, ",")(0)
cm = New OleDbCommand(strsql, cn)
cn.Open()
dr = cm.ExecuteReader()
While dr.Read()
ComboBox3.Items.Add(dr.Item(0) &","& dr.Item(1) &","& dr.Item(2) &","& dr.Item(3))
End While
cn.Close()
ComboBox3.Select()
ComboBox3.Text = ComboBox3.Items.Item(0)
End Sub
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim x As Integer = DataGridView1.Columns.Count()
Dim i As Integer = 0
For i = 0 To x : DataGridView1.Columns.Clear() : Next
strsql = "select * from employees "
strsql &= "where employeeid = " & Split(ComboBox3.Text, ",")(2)
cm = New OleDbCommand(strsql, cn)
cn.Open()
dr = cm.ExecuteReader()
If dr.Read() Then
x = DataGridView1.Rows.Count()
DataGridView1.Columns.Add("eid", "eid")
DataGridView1.Columns.Add("ename", "ename")
DataGridView1.Rows.Add()
DataGridView1.Rows(x).Cells(0).Value = dr.Item(0)
DataGridView1.Rows(x).Cells(1).Value = dr.Item(1)
End If
cn.Close()
End Sub
End Class
|