我的 Visual Basic 程序从 Access 数据库中获取值并将它们放在标签中。从数据库返回的数据取决于在组合框中选择的值,并且应该随着组合框值的变化而变化,但令我惊讶的是,即使它们必须更改,标签仍然只显示最先显示的第一个值。我试图在每次访问数据库之前将标签文本分配给任何内容,但它仍然显示以前的值。我无法让这些标签更改文本可能是什么问题?请帮忙。这是我用来访问数据库并放入标签的代码:
Me.p.Text = Nothing
Me.tq.Text = Nothing
Me.pd.Text = Nothing
Me.ba.Text = Nothing
Me.o.Text = Nothing
Me.pm.Text = Nothing
Me.tv.Text = Nothing
Me.tqr.Text = Nothing
Me.dff.Text = Nothing
Try
cmd.Connection = cnn
cmd2.Connection = cnn
cmd3.Connection = cnn
cmd.CommandText = "SELECT distinct(brought_price), sum(brought_qtty), sum(brought_paid), sum(brought_bal),recieved_qtty,sum(brought_qtty)-recieved_qtty, sum(brought_qtty)*brought_price from brought_coffee, farmer, centre_weigh " & _
"where brought_date=? and farmer_centre=? and" & _
" brought_coffee.farmer_num=farmer.farmer_num and weigh_date=? and weigh_centre=? and brought_coffee.brought_date=centre_weigh.weigh_date and farmer_centre=weigh_centre group by brought_price,recieved_qtty"
MessageBox.Show(Me.dtc.Text)
cmd.Parameters.Add("@dt", OleDb.OleDbType.Date).Value = Me.dtc.Text
cmd.Parameters.Add("@dt2", OleDb.OleDbType.VarChar).Value = Me.cc.Text.Trim.Substring(0, 2)
cmd.Parameters.Add("@dt3", OleDb.OleDbType.Date).Value = Me.dtc.Text
cmd.Parameters.Add("@dt4", OleDb.OleDbType.VarChar).Value = Me.cc.Text.Trim.Substring(0, 2)
cmd2.CommandText = "SELECT sum(brought_qtty) from brought_coffee,farmer where coffee_grade='O' and brought_date=? and farmer_centre=? and" & _
" brought_coffee.farmer_num=farmer.farmer_num"
cmd2.Parameters.Add("@dt5", OleDb.OleDbType.Date).Value = Me.dtc.Text
cmd2.Parameters.Add("@dt6", OleDb.OleDbType.VarChar).Value = Me.cc.Text.Trim.Substring(0, 2)
cmd3.CommandText = "SELECT sum(brought_qtty) from brought_coffee,farmer where coffee_grade='P' and brought_date=? and farmer_centre=? and" & _
" brought_coffee.farmer_num=farmer.farmer_num"
cmd3.Parameters.Add("@dt7", OleDb.OleDbType.Date).Value = Me.dtc.Text
cmd3.Parameters.Add("@dt8", OleDb.OleDbType.VarChar).Value = Me.cc.Text.Trim.Substring(0, 2)
myData = cmd.ExecuteReader
myData2 = cmd2.ExecuteReader
myData3 = cmd3.ExecuteReader
'MessageBox.Show("check 1")
While myData.Read()
'MessageBox.Show("check 1")
Dim pr As String = myData(0).ToString
Dim qtty As String = myData(1).ToString
Dim pd As String = myData(2).ToString
Dim bl As String = myData(3).ToString
Dim rq As String = myData(4).ToString
Dim dq As String = myData(5).ToString
Dim tvp As String = myData(6).ToString
'MessageBox.Show("quantity" & pr)
Me.p.Text = pr
Me.tq.Text = qtty
Me.pd.Text = pd
Me.ba.Text = bl
Me.tqr.Text = rq
Me.dff.Text = dq
Me.tv.Text = tvp
End While
myData.Close()
While myData2.Read()
Dim od As String = myData2(0).ToString
'MessageBox.Show(od)
Me.o.Text = od
End While
myData2.Close()
While myData3.Read()
Dim pmm As String = myData3(0).ToString
Me.pm.Text = pmm
End While
myData3.Close()
cnn.Close()
dtc
并且cc
是与选定的数据库值进行比较的文本框