Question

I am working with a pos system in c#, I am having a database with SQL 2008 and c# is my programming language. my problem is when I enter item code to a text box it will find the Idem name and unit price and quantity available details. for that i am using a search with Keydown event

 private void textBoxItemCode_KeyDown_1(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {

                string SQLStatement = "Select * from Stock_Entry where Item_Code='" + textBoxItemCode.Text + "'";
                SqlDataReader myreader = DBConnection.viewDetails(SQLStatement);
                if (myreader.Read())
                {
                    textBoxItemName.Text = (string)myreader["Item_Name"];
                    Textbox_Category.Text = (string)myreader["Categary"];
                    textBoxItemPrice.Text = (string)myreader["Unit_Price"];
                    label_avlQty.Text = (string)myreader["No_of_Items"];

                }

    }
    }

but my problem is i need to do the same function with a cell in datagridview. when I enter a item code into a cell i want to find the details with that what event i can handle.

Était-ce utile?

La solution

This may help.

On a different topic, you are leaving yourself wide open to SQL injection attacks (do some research).

Consider what would happen if I typed this into the text box:

';DELETE FROM Stock_Entry;SELECT * FROM Stock_Entry where Item_Code='

Also, you are going back to the DB on every single key press i.e. item code 123456 requires 6 (slow) database calls, if you read 1% into local data and then queries this against 12%, 123% etc things may be a lot quicker.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top