oledbcommand sql查询奇怪的行为 [英] oledbcommand sql query strange behaviour
问题描述
你好,
我有一个sql搜索查询的奇怪行为,我已经向sql查询中的oledbcommand对象添加了参数,我使用了一个组合框来选择适当的参数,奇怪的是在设计时我预览数据并赋予值其中一个参数可以正确显示数据,但是在运行时,当我使用combobox itemindex时,它仅适用于其中三个参数,其他五个则不给出任何结果,但是在设计时它给出了结果.有帮助吗?
预先谢谢您
Hello,
I have a strange behaviour of an sql search query, I have added parameters to an oledbcommand object in an sql query, I use a combobox to select the appropriate parameter, the strange thing is at design time when I preview the data and give value to one of the parameters it displays the data correctly, but at runtime when I use the combobox itemindex it works only for 3 of the parameters other 5 it dosn''t give any results but at design time it gives results. Any help?
Thank you in advance
推荐答案
代码是这里,但是我想知道vb 2008是否没有Service Pack 1,也许我必须更新? >
oledbcommand中的sql命令(请注意,在设计时预览数据"该命令有效)
Here is the code but I wonder if it has to do that vb 2008 is without service pack 1, maybe I must update?
sql command in oledbcommand (note that in design time "preview data" the command works)
SELECT id, car_num, owner, afm1, address, phone, owner2, afm2, address2, phone2, owner3, afm3, address3, phone3, comments, photo, plaisio_num,
speciment_of_vechicle, type_of_vechicle, ead, product_facilities, onoma_patros, doy
FROM dbo.Table_1
WHERE (car_num LIKE '%' + ? + '%') OR
(owner LIKE ? + '%') OR
(afm1 LIKE ? + '%') OR
(address LIKE ? + '%') OR
(phone LIKE ? + '%') OR
(owner2 LIKE ? + '%') OR
(owner3 LIKE ? + '%') OR
(plaisio_num LIKE ? + '%') OR
(ead LIKE ? + '%')
这是Serach按钮代码(组合索引0,5,7,8起作用并给出结果)
and here is the serach button code (combo index of 0,5,7,8 works and gives the results)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Select Case ComboBox1.SelectedIndex
Case 0
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(0).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 1
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(1).Value=TextBox1.Text OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 2
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(2).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 3
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(3).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 4
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(4).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 5
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(5).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 6
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(6).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 7
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(7).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
Case 8
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.Parameters(8).Value = TextBox1.Text
OleDbDataAdapter1.Fill(DataSet51, "Table_1")
OleDbConnection1.Close()
End Select
End Sub
这篇关于oledbcommand sql查询奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!