I want to pass multiple select queary to datareader. how to do it.

I know how to pass queary for one condition :

SqlConnection cn = new SqlConnection();
            cn.ConnectionString = "";
            cn.Open();
            SqlCommand cmd = new SqlCommand();
            SqlDataReader rdr;
            string s = "select * from abc where id like@find";
            cmd = new SqlCommand(s);
            cmd.Parameters.Add(new SqlParameter("@find", System.Data.SqlDbType.VarChar, 20, "find"));
            cmd.Parameters["@find"].Value = textBox1.Text;
            rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                comboBox1.Items.Add(rdr["id"].ToString());
            }
            rdr.Close();

program should check for name if id and name both are correct then data display in combobox.

thanks........

And how do you want to choose different conditions? I really dont understand your question. Please elaborate this issue of yours a bit better.
Do you write any text into textBox, and thats why you use LIKE condition?
If so, you have to change the code to:

string _value = textBox1.Text;
//rest of code, and:
string s = "SELECT id FROM abc WHERE id LIKE 'find%'";
cmd.Parameters.Add("@find", System.Data.SqlDbType.VarChar, 20).Value = _value;
//rest of code...

I have database in sql 2005 in that table name is abc
I want to display the list of those student whose name start from textbox1.text data and there class mut be same if both condions are true then there name dispaly in combobox.

if ((class = 1) && (name = "A"))

Then do the query liek this:

string _value = textBox1.Text;
//rest of code, and:
string s = "SELECT id FROM abc WHERE id LIKE 'find%' AND class = @class";
cmd.Parameters.Add("@find", System.Data.SqlDbType.VarChar, 20).Value = _value;
cmd.Parameters.Add("@class", System.Data.SqlDbType.int).Value = 1;

it works.

thanks.....

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.