hay guys...

i m new here and having problem in finding a row through a combobox i did that with a simple text box it is working fine here is the coding

private void btnFind_Click(object sender, EventArgs e)
        {
            string searchFor = textBox4.Text;
            int results = 0;
            DataRow[] returnedRows;
            
            returnedRows = ds1.Tables["Workers"].Select("last_Name ='" + searchFor + "'");

            results = returnedRows.Length;

            if (results > 0)
            {
                DataRow dr1;

                dr1 = returnedRows[0];
                MessageBox.Show(dr1["Last_Name"].ToString());
            }
            else
            {
                MessageBox.Show("No such Record");
            }
        }

but now i want to have a combobox from where i can select any of the three columns that is First_Name, Last_Name and Job_Title (i know first name wont be suitable for search but its just prototype) and whatever i select and write respective field in a text box and press find so it should show the respective match here is my code in which m having problem

private void btnFind_Click(object sender, EventArgs e)
        {
            string searchFor = textBox4.Text;
            int results = 0;
            DataRow[] returnedRows;
            
            returnedRows = ds1.Tables["Workers"].Select(comboBox1.Text+"='" + searchFor + "'");

            results = returnedRows.Length;

            if (results > 0)
            {
                DataRow dr1;

                dr1 = returnedRows[0];
                MessageBox.Show(dr1[comboBox1.Text].ToString());
            }
            else
            {
                MessageBox.Show("No such Record");
            }
        }

string searchFor = textBox4.Text;

use SelectedItem property of comboBox:

comboBox1.Selecteditem.ToString();

Thnks man... i've tried this in my prototype working fine there thnks again

No problem. You can mark the thread as answered now.
thx ina advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.