【发布时间】:2015-02-13 06:29:41
【问题描述】:
我想知道在从组合框中选择另一个值后是否可以刷新当前的窗体,以便在其他几个文本框中显示该项目的详细信息?
所以我的桌子看起来像 表名:程序 程序 ID 程序名称 程序描述 1 T1 描述1
这是我使用 atm 的代码
Dim connection As New SqlClient.SqlConnection
connection.ConnectionString = "pathway"
Dim dr As SqlDataReader
Dim prognamedesc As String
Dim filetypetxt As String
Dim prognamecombo As String
Dim filetypecombo1 As String
Dim command As New SqlCommand
Dim querycommand As New SqlCommand
connection.Open()
'THIS SECTION LOADS DATA FROM THE TABLES'
Try
command.Connection = connection
command.CommandType = CommandType.Text
command.CommandText = "select program_name,filetype from program order by program_name; select * from filetype"
querycommand.Connection = connection
querycommand.CommandType = CommandType.Text
querycommand.CommandText = "select program_name,program_desc , filetype from program where program_name like" & FiletypeComboBox1.SelectedItem & ""
dr = command.ExecuteReader
While dr.Read()
prognamecombo = dr(0)
Program_nameComboBox.Items.Add(prognamecombo)
End While
dr.NextResult()
While dr.Read()
filetypecombo1 = dr(0)
FiletypeComboBox1.Items.Add(filetypecombo1)
FiletypeComboBox1.SelectedItem = filetypecombo1
End While
dr.NextResult()
While dr.Read()
filetypetxt = dr(0)
FiletypeLabel1.Text = filetypetxt
End While
dr.NextResult()
While dr.Read()
prognamedesc = dr(0)
Program_descTextBox.Text = prognamedesc
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
connection.Close()
我想知道使用当前代码是否可行?
【问题讨论】:
-
你所追求的可能是一个事件过程。更改组合框选择后触发的过程。应该有一个事件你可以查到它叫做
_Changed()Combobox 控件的事件。 -
它是我创建另一个私有子并将结果传递到输出区域的地方吗?据我了解,一旦我从组合框中选择了一个项目,页面就需要使用与组合框中的项目相关联的信息进行刷新。我尝试过重新查询,但不知何故它根本没有出现。 me.refresh 也不做任何事情。
-
Google it :) 有大量关于 VBA 事件过程的信息和教程
-
在我决定问之前已经在 Google 上待了几个小时。我在 Youtube 上看过一个例子,但是它需要我改变程序的整个结构。
-
我在想这是否可行 检测是否已单击组合框 以某种方式发送新查询并显示结果。