在VB.net中如何将下拉列表中的内容传到文本框中
我在“选择列名”的下拉列表中可以显示表中所有的列名,我想达到这样一个目的:我在“选择列名”中选择一个列,然后在“筛选相关”的文本框中输入一个列的具体值,利用模糊查询,将查...
我在“选择列名”的下拉列表中可以显示表中所有的列名,我想达到这样一个目的:我在“选择列名”中选择一个列,然后在“筛选相关”的文本框中输入一个列的具体值,利用模糊查询,将查询的结果显示在上面。代码如下:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ComboBox2.Text = "" Then
MessageBox.Show("请选择要进行筛选的列名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ComboBox2.Focus()
Exit Sub
End If
Dim str As String
str = ""
If TextBox6.Text.Trim <> "" Then str = str & " and like '%" & TextBox6.Text & "%'"
If str <> "" Then
str = " where " & str.Substring(5)
End If
Try
ds.Clear()
da = New SqlClient.SqlDataAdapter("select * from 入库表 " & str, con)
da.Fill(ds, "入库表")
dt = ds.Tables("入库表")
DataGrid1.DataSource = dt
DataGrid1.Refresh()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Button2指筛选按钮,主要是这一行:If TextBox6.Text.Trim <> "" Then str = str & " and like '%" & TextBox6.Text & "%'"我在and和like 之间输入具体的列名,可以查询,但是我要的是下拉列表中的列名,然后查询,本人不会连,很郁闷! 展开
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If ComboBox2.Text = "" Then
MessageBox.Show("请选择要进行筛选的列名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ComboBox2.Focus()
Exit Sub
End If
Dim str As String
str = ""
If TextBox6.Text.Trim <> "" Then str = str & " and like '%" & TextBox6.Text & "%'"
If str <> "" Then
str = " where " & str.Substring(5)
End If
Try
ds.Clear()
da = New SqlClient.SqlDataAdapter("select * from 入库表 " & str, con)
da.Fill(ds, "入库表")
dt = ds.Tables("入库表")
DataGrid1.DataSource = dt
DataGrid1.Refresh()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Button2指筛选按钮,主要是这一行:If TextBox6.Text.Trim <> "" Then str = str & " and like '%" & TextBox6.Text & "%'"我在and和like 之间输入具体的列名,可以查询,但是我要的是下拉列表中的列名,然后查询,本人不会连,很郁闷! 展开
2个回答
展开全部
在下拉菜单的SelectionChangeCommitted事件中调用Button2_Click
Private Sub 选择列名ComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles 病情ComboBox.SelectionChangeCommitted
Button2_Click(sender, e)
End Sub
我不是很懂你的意思,如果你要用combox里的数据那就在and like之间加个
选择列名ComboBox.text
不就得了
Then str = str & " and " & 选择列名ComboBox.text & " like '%" & TextBox6.Text
Private Sub 选择列名ComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles 病情ComboBox.SelectionChangeCommitted
Button2_Click(sender, e)
End Sub
我不是很懂你的意思,如果你要用combox里的数据那就在and like之间加个
选择列名ComboBox.text
不就得了
Then str = str & " and " & 选择列名ComboBox.text & " like '%" & TextBox6.Text
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询