根据所选的组合框项目在文本框中显示数据,其中它等于查询值 [英] show data on textbox according to the selected combobox item where it is equal to the query value
本文介绍了根据所选的组合框项目在文本框中显示数据,其中它等于查询值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
那里的优点,
我的情况:
i想要根据所选组合框项目显示文本框上的数据,其中它等于查询值。
Faced Error msg:
语法不正确=。< br $> b $ b
我的问题:
有人来找我的问题吗?这是我的查询声明错了吗?
我的代码:
尝试
如果connection.State = ConnectionState.Closed那么
connection.Open()
结束如果
Dim ss As String = ComboBox2.SelectedItem。 Trim()
Dim update1 As String =SELECT * FROM devicetbl WHERE dname =& ss&
Dim cmd As New SqlCommand(update1,connection)
Dim dare As SqlDataReader = cmd.ExecuteReader()
if dare.HasRows then
dare.Read ()
TextBox3.Text = dare.Item(IP)
TextBox4.Text = dare.Item(Port)
dare.Close()
End If
Catch ex As Exception
MsgBox(ex.Message)
结束尝试
connection.Close()
解决方案
您的查询错误。您需要单引号,因为您正在处理字母数字值。
SELECT * FROM devicetbl WHERE dname ='& ss&
Pros out there,
My case:
i want to show data on textboxes according to the selected combobox item where it is equal to the query value.
Faced Error msg:
"Incorrect Syntax near =."
My Question:
can anybody come and look for my problem? is it my query statement wrong?
My Codes:
Try If connection.State = ConnectionState.Closed Then connection.Open() End If Dim ss As String = ComboBox2.SelectedItem.Trim() Dim update1 As String = "SELECT * FROM devicetbl WHERE dname = " & ss & "" Dim cmd As New SqlCommand(update1, connection) Dim dare As SqlDataReader = cmd.ExecuteReader() If dare.HasRows Then dare.Read() TextBox3.Text = dare.Item("IP") TextBox4.Text = dare.Item("Port") dare.Close() End If Catch ex As Exception MsgBox(ex.Message) End Try connection.Close()
解决方案
Your query is wrong. You need single quotes since you are dealing with alphanumeric values.
"SELECT * FROM devicetbl WHERE dname = '" & ss & "'"
这篇关于根据所选的组合框项目在文本框中显示数据,其中它等于查询值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文