I have a DataTable with the following schema and sample data:
ProductID | LocationID | ProductName | Quantity | SellingPrice
---------------------------------------------------------------------
1 | 1 | xyz | 10 | 5.0000
1 | 2 | xyz | 15 | 5.0000
2 | 1 | abc | 10 | 7.0000
3 | 1 | def | 30 | 9.5000
3 | 2 | def | 60 | 9.5000
When I bind this datasource to a combobox (DisplayMember = ProductName, ValueMember = ProductID), some products are repeated. How can I only show distinct results in the combobox

how to filter out duplicate values?
Catalin Criveteanu
If that's true, simply make 2 SQL statements. If you're using SQL Server, you can do that with a single stored procedure.
On the other hand if this <u>IS</u> coming from a single table, you have a problem with the first rule of data normalization and you should fix that first.
John Long
I am making an accounting application where (apart from a lot of other things) the user can enter sales invoices. The DataTable I posted above is used to verify that any product entered in the invoice does not fall below stock (location is selected by the user) and to give the user a warning if it is sold below cost. For this purpose, the ProductName column is not required. But I added it so that I could use the same information to populate the combobox (which is actually in the DataGrid as a DataGridComboBoxColumn). I thought I could filter out duplicate products through the DataView or something. I don't think that is possible, is it
Oh yeah, and I <em>am</em> using SQL Server.
Now, as per your advice, if I use a DataReader to populate the DataTable, will this not affect the performance of my application Let's say I have about 300 products and 2 location where the products are stored. So that is 300 iterations to populate the DataTable for the combobox and another 300 X 2 = 600 iterations for the DataTable to store the stock and price information. A total of 900 iterations in the constructor (or FormLoad event).
kneeride
I don't know if I have understood what you mean. Are you suggesting that I do not join the tables in the SQL query, rather retrieve two tables as they are and then join them in the DataSet via a DataRelation
fewfewfew
I completely agree with making as few round trips to the data source as possible and you question intonates that concern. It is possible to make a single trip to a SQL Server (for instance) and grab this DataTable and a 2nd one made just for your drop down in one quick visit.
If you are using SQL Server (I don't know that you are), you simply place 2 valid SQL statements that each return the set of data you want in a single stored procedure. Ensure you define the ends of those SQL statements with a semi-colon ";" so SQL Server knows they are 2 different calls.
Then, retrieve your data from this stored procedure just like any other stored procedure and what you will get is the first set of data. To move to the next set, use the ".NextResult" method on your SqlDataReader object to point to the 2nd set of data you defined in your stored procedure.
I don't have all your information so I've made a lot of assumptions. I don't know how much it will help. Good luck anyway.
Andy Tischaefer - MSFT
I don't know if it is appropriate for me to post this here, but I would like to draw your attention to another post [<post>7496</post>] that is related to the same stuff that I am doing.
Tominator2005
<a href="http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconsettingupdatatabledatacolumnmappings.asp">Setting Up DataTable and DataColumn Mappings</a>
<a href="http://www.dotnet247.com/247reference/msgs/28/143418.aspx">See David Sceppa's Explination near the bottom of this page</a>
LeCoop
Ernesto Vasquez.
As for using a DataReader as opposed to a DataTable, forget I said DataReader. In your case, you'll want to use a DataAdapter and TableMappings to fill multiple DataTables in the same DataSet at the same time.
Here's another alternative using SQLXML that I just found:
<a href="http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnhcvb03/html/vb03e9.asp">Populating a Multi-table DataSet with SQLXML</a>