将来自combobox的输入作为sql查询的参数 [英] taking input from combobox as an parameter to an sql query

查看:90
本文介绍了将来自combobox的输入作为sql查询的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从组合框中选择一个文本,并将其作为sql查询的参数

我写了如下查询:

i want to select a text from an combo box and give that as a parameter to an sql query

i have written the query as below:

Dim strSelect As String = "SELECT * FROM Table1 WHERE city='ComboBox1.SelectedItem()'"
Dim da As New OleDbDataAdapter(strSelect, con)
Dim ds As New DataSet
da.Fill(ds, "city")





但是我遇到错误,请告诉我如何编写查询以接受来自组合框的输入

感谢





but i am getting error ,can u please tell me how to write query to accept input from combobox

thanks

推荐答案

尝试一下:

Try this:

Dim strSelect As String = string.Format("SELECT * FROM table1 WHERE city='{0}'", ComboBox1.SelectedItem)


我认为选择字符串应该是这样的-
I think select string should be something like this -
Dim strSelect As String = "SELECT * FROM Table1 WHERE city='" & ComboBox1.SelectedItem() & "'"


Dim strSelect As String = "SELECT * FROM Table1 WHERE city='" & ComboBox1.SelectedItem& "'"


这篇关于将来自combobox的输入作为sql查询的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆