Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Mysql to Datagridview duplicate values

Tags:

c#

mysql

I have a problem with the following code:

MySqlConnection conDatabase = new MySqlConnection(myConne);
MySqlCommand cmdDataBase = new MySqlCommand("Select * from supplier_data,brands where brands.supplier_id = supplier_data.supplier_id ", conDatabase);
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase;
System.Data.DataTable dbdataset = new System.Data.DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView3.DataSource = bSource;
sda.Update(dbdataset);

When it displays into datagridview, if one supplier has two brands, duplicates received data but with other brand.

like image 419
Berea Adrian Avatar asked Jan 23 '26 18:01

Berea Adrian


1 Answers

You can group the result by using group-by, So attach the following at the end of your query

Group By brands.supplier_id

like image 180
sujith karivelil Avatar answered Jan 26 '26 09:01

sujith karivelil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!