vb combobox控件下拉列表我想改成显示的是中文如:{部门编号,部门名称},而对应数据库的值是{bmbh,bmmc}
按条件查询原代码和combobox如下怎么改PrivateSubcx_Click(ByValsenderAsSystem.Object,ByValeAsSystem.Ev...
按条件查询
原代码和combobox如下
怎么改
Private Sub cx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cx.Click
Dim myconn1 As New SqlConnection
Dim mycmd1 As New SqlCommand
myconn1.ConnectionString = zfc
myconn1.Open()
mycmd1.Connection = myconn1
Dim com1 As String = ComboBox2.Text
com1 = ComboBox2.Text
Dim tex1 As String = TextBox2.Text
If tex1 <> "" Then
mycmd1.CommandText = "select * from bm where " & com1 & " like '%" & tex1 & "%'"
Else
mycmd1.CommandText = "select * from bm "
End If
Dim mydataap As New SqlDataAdapter(mycmd1)
Dim myds As New DataSet()
mydataap.Fill(myds, "bm")
DataGridView2.DataSource = myds.Tables("bm")
mycmd1.Clone()
myconn1.Close()
End Sub
End Class 展开
原代码和combobox如下
怎么改
Private Sub cx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cx.Click
Dim myconn1 As New SqlConnection
Dim mycmd1 As New SqlCommand
myconn1.ConnectionString = zfc
myconn1.Open()
mycmd1.Connection = myconn1
Dim com1 As String = ComboBox2.Text
com1 = ComboBox2.Text
Dim tex1 As String = TextBox2.Text
If tex1 <> "" Then
mycmd1.CommandText = "select * from bm where " & com1 & " like '%" & tex1 & "%'"
Else
mycmd1.CommandText = "select * from bm "
End If
Dim mydataap As New SqlDataAdapter(mycmd1)
Dim myds As New DataSet()
mydataap.Fill(myds, "bm")
DataGridView2.DataSource = myds.Tables("bm")
mycmd1.Clone()
myconn1.Close()
End Sub
End Class 展开
1个回答
展开全部
你的意思是 combox里面的内容是设置好的?相当于查询备选 文字?然后选了就填入textbox?
追问
也可以代码添加啊,是想把查询中的下拉列表框里的字段全部换成实际的查询字段,比如:姓名,年龄等等这
我的部门表里的属性是bmbh和bmmc(拼音的)
按条件查询combobox里面的字段想设成中文,易懂,可是这样我不知道怎么关联到数据库的拼音字段
追答
哦,我的建议:
1:修改数据库字段,字段修改为汉字。
2:combox里面设置汉语,查询的时候,经过一个简单转换。
比如
if combox.text="姓名" then str=bmbh
增加中间步奏即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询