从表中选择*,例如..%... with And [英] Select * from table like..%... with And
本文介绍了从表中选择*,例如..%... with And的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i在桌城,乡村有两个字段。
i有两个文本框格式。
i想要使用所有文本框作为搜索...
如果我写的话
city :新国家:团结
或
city:york国家:uni
在文本框中,然后点击搜索,结果应该是...
纽约,美国。
我试过......
hi all,
i have two field in table city,country.
i have two textboxes in form.
i want to use all textboxes as search like...
if i write
city : new Country : unite
or
city : york Country : uni
in textbox and then click on search so result should be...
new york, united state.
I tried...
ss = "select * from Master where city like'%" + txtCity.Text + "%' and country like'%" + txtCountry.Text + "%'"
推荐答案
使用参数化查询防止sql注入和它还可以为你节省很多语法:
Use parameterized query to prevent sql injection and it will also save you a lot of syntax mess:
ss = "select * from Master where city like @city and country like @country";
cmd.Parameters.AddWithValue("@city", "%" + txtCity.Text +"%");
cmd.Parameters.AddWithValue("@country", "%" + txtCountry.Text +"%");
了解更多:sqlcommand.parameters [ ^ ]
试试这个.. :)
try this.. :)
"select * from Master where city like '%" + txtCity.Text + "%' and country like '%" + txtCountry.Text + "%'";
ss = "select * from Donator where sname like @sname and city like @city and atpo like @atpo and taluka like @taluka and dist like @dist and pin like @pin" & _
" and letter like @letter and notes like @notes and other like @other" ' and email like @email"
com = New OleDbCommand(ss, con)
com.Parameters.AddWithValue("@sname", "%" + TextBox12.Text + "%")
com.Parameters.AddWithValue("@city", "%" + TextBox13.Text + "%")
com.Parameters.AddWithValue("@atpo", "%" + TextBox14.Text + "%")
com.Parameters.AddWithValue("@taluka", "%" + TextBox15.Text + "%")
com.Parameters.AddWithValue("@dist", "%" + TextBox16.Text + "%")
com.Parameters.AddWithValue("@pin", "%" + TextBox17.Text + "%")
com.Parameters.AddWithValue("@letter", "%" + TextBox19.Text + "%")
com.Parameters.AddWithValue("@notes", "%" + TextBox20.Text + "%")
com.Parameters.AddWithValue("@other", "%" + TextBox21.Text + "%")
con.Open()
dr = com.ExecuteReader()
While dr.Read
x = DataGridView1.Rows.Add(+1)
DataGridView1.Rows(x).Cells(0).Value = dr(0)
DataGridView1.Rows(x).Cells(1).Value = dr(2)
DataGridView1.Rows(x).Cells(2).Value = dr(1)
DataGridView1.Rows(x).Cells(3).Value = dr(3)
address = dr(4) + ", " + dr(5) + ", " + dr(6) + ", " + dr(7) + ", " + dr(25) + ", " + dr(8) + ", " + dr(9) + ", " + dr(10)
DataGridView1.Rows(x).Cells(4).Value = address
DataGridView1.Rows(x).Cells(5).Value = dr(11)
address1 = dr(12) + ", " + dr(13) + ", " + dr(14) + ", " + dr(15) + ", " + dr(26) + ", " + dr(16) + ", " + dr(17) + ", " + dr(18)
DataGridView1.Rows(x).Cells(6).Value = address1
DataGridView1.Rows(x).Cells(7).Value = dr(19)
DataGridView1.Rows(x).Cells(8).Value = dr(20)
DataGridView1.Rows(x).Cells(9).Value = dr(21)
DataGridView1.Rows(x).Cells(10).Value = dr(22)
DataGridView1.Rows(x).Cells(11).Value = dr(23)
End While
con.Close()
这篇关于从表中选择*,例如..%... with And的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文