Click here to Skip to main content
15,354,523 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m making a project and is having problem in searching from the database. I m searching on the basis of "name" which is a 'combobox' and there are two 'textboxes' for color and price and one 'numericupdown' for quantity which is to be retrieved from database.
So please tell me how to write code in try().

Updated 18-Jul-16 5:33am
Nicholas Marty 15-Nov-13 5:57am
Please provide some information about how you're trying to access the database.

1 solution

We can't be explicit, because we have no idea how your system works, but this is the general idea:
using (SqlConnection con = new SqlConnection(strConnect))
    using (SqlCommand cmd = new SqlCommand("SELECT iD, description FROM myTable WHERE Name LIKE '%' + @NM + '%'", con))
        cmd.Parameters.AddWithValue("@NM", myNameTextBox.Text);
        using (SqlDataReader reader = cmd.ExecuteReader())
            while (reader.Read())
                int id = (int) reader["iD"];
                string desc = (string) reader["description"];
                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
Clearly, you will need to modify the WHERE clause to fit your circumstances at the minimum.
♥…ЯҠ…♥ 15-Nov-13 6:02am

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