I want to search data from combo box here is the code :

SqlConnection cn = new SqlConnection(s);
            SqlCommand cmd = new SqlCommand();
            SqlDataReader rdr;
            string cd =comboBox1.Text.ToString();
            string CommandText = "select * from rto where cd =@cd";
            cmd = new SqlCommand(CommandText, cn);
            cmd.Parameters.Add(new SqlParameter("@cd", System.Data.SqlDbType.VarChar, 20, "cd"));
            cmd.Parameters["@cd"].Value =comboBox1.Text.ToString();
            rdr = cmd.ExecuteReader();
            while (rdr.Read())
                textBox1.Text = rdr["cd"].ToString();
                textBox2.Text = rdr["area"].ToString();
                textBox3.Text = rdr["addr"].ToString();

This code run without an error but not displaying any contents in combo box.

I don't see anything obviously wrong so I'd guess your SQL isn't returning anything.

I dont know why this happend but it does not display any information what should i do the changes in sql or c#

I haven't found any code block above, where you are filling your combobox. you are querying from database based on inputs of the combo.. But in your post you are saying no value is coming in combo box...??? its really confusing... :-O

yes I understand it after some time and i have written the code to fill content in combobox and its working. I am realy very sorry for posting like this queary.

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.