搜索按钮问题 [英] Search button probleam
本文介绍了搜索按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai,我的按钮搜索问题出了问题.执行此代码后出现错误,错误是未处理InvalidOperationException.如果缺少部分,请更正我的代码.我正在使用sql server 2005和ms visual studio2005.我还突出显示了导致此错误的行
Hai, i have probleam with my button search probleam .I got an error after i execute this code , the error is InvalidOperationException was unhandled.Please correct my coding if it have missing part . I am using sql server 2005 and ms visual studio 2005. I also have highlight which line cause this error
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchItem.Click
Dim Dr As OleDbDataReader
Dim Con As New OleDb.OleDbConnection("Provider=SQLOLEDB ;Data Source=Danawa;Initial Catalog=Store;Integrated Security=SSPI ")
Con.Open()
Dim Trans = Con.BeginTransaction
Dim cmd As New OleDb.OleDbCommand("SELECT ItemName, Itemquantity ,Catagory,ItemPrice, Supplier ,Total FROM ItemIn = '" & txtSearchItem.Text & "' ", Con)
Dr = cmd.ExecuteReader() // This line cause an error//
Try
If Dr.Read = False Then
MsgBox("Item Name Is Not Found!!", MsgBoxStyle.Exclamation)
Else
ItemNameTextBox1.text = Dr("ItemName")
ItemquantityTextBox1.text = Dr("Itemquantity")
CatagoryTextBox.text = Dr("Catagory")
ItemPriceTextBox1.text= Dr("ItemPrice")
SupplierComboBox.text= Dr("Supplier")
TotalMaskedTextBox.text= Dr("Total")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Trans.Commit()
Dr.Close()
If Con.State <> ConnectionState.Closed Then
Con.Close()
End If
end sub
推荐答案
您错过了WHERE一词:
You missed out the word WHERE:
SELECT ... FROM table WHERE field=value
另请参阅我对其他问题的有关SQL注入的评论.
Also see my comment about SQL injection on your other question.
检查您的查询-里面没有WHERE和列名
它应该是-
Check your query-- it dont have WHERE in it and column name
it should be-
im cmd As New OleDb.OleDbCommand("SELECT ItemName, Itemquantity ,Catagory,ItemPrice, Supplier ,Total FROM Item WHERE (column_name) = ''" & txtSearchItem.Text & "'' ", Con)
这篇关于搜索按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文