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 = "";
            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())

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


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...

Edited 5 Years Ago by Mitja Bonca: n/a

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;
This question has already been answered. Start a new discussion instead.