Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
 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
Posted
Updated 11-Oct-11 8:48am
v2

You missed out the word WHERE:
SQL
SELECT ... FROM table WHERE field=value

Also see my comment about SQL injection on your other question.
 
Share this answer
 
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)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900