Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i've 3 columns name, log_no & country
i want when choose country from combobox show the related data "name & log_no"
on datagridview
wait ur help
Posted

select * from tablename where country=combobox.selectedItem


use this query to bind datagridview in selection changed event of combobox
 
Share this answer
 
v2
Something like the following. Include the proper connection and modify the table name and the object names corresponding to your project.

C#
            SqlCommand command = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable dt = new DataTable();
            
            //command.Connection = connection;
            command.CommandText = @"
SELECT  a.Name,
        a.Log_No
FROM    Table   a
WHERE   a.Country = :country";
            command.Parameters.AddWithValue("country", cmbCountry.Text);
            da.SelectCommand = command;
            da.Fill(dt);
            command.Dispose();
            dataGridView1.DataSource = dt;
 
Share this answer
 

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