can this be done

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I'm creating a dataset and get my data from the db table such as PA, PA, WA,
WA CA, DE, DE, DE, FL, WI. is there a way to do a select on that dataset and
populate a drop down box such as CT, DE, FL, WI?

i don't want to see multiple DE's or PA's, etc.


thx
 
Hi,

The easiest way to do this is when you get the data from the DB. Do a
"Select Distinct" instead of a regular select. For example:

Select
State
From
Orders

This will give you the data you showed first...lots of repeats. So instead
do:

Select Distinct
State
From
Orders

Now you will get each state only once. One tip I will give you about data
and queries is never to forget about the
microsoft.public.sqlserver.programming group. SQL isn't my specialty and I
have learned a *TON* from those guys. Not to mention they totally saved my
butt once. Whenever I catch myself using excessive code to wrangle data I
received from a query I go there first to figure out how to make a better
query. Good luck! Ken.
 
I'm calling a stored procedure and getting the data. I'm already using the
dataset to populate a datagrid and i was wondering if I could use that same
dataset to populate the combo box without making another trip to the
database
 
Hi Mike,

I'm assuming you are using ADO.Net. I don't know a way to do what you want,
however someone may know and get right back to you on it. The neat thing
about ADO.Net is that you can do what you want with minimal effort and only
one call to the DB. ADO.Net returns all your Selects. Not just the last
one you performed. So give this a try modifying my pseudo code from before
to work for your needs. In the query you are running to fill that data grid
put this in a way it makes sense for you at the bottom of that query:

Select Distinct
State
From
Orders

Basically, that represents the 2nd query (i.e. 2nd trip to DB). Now check
out what you get back! Use the debugger and you'll see that not only is
your objDataSet.Tables(0) filled with data, but your objDataSet.Tables(1) is
also filled with the other query. Now you have both sets of data, one DB
trip, and at a very minimal cost in respect to your States lookup. I know
this isn't the same as running a query on the one dataset you have in your
hands but it may be a solution for you. Good luck! Ken.
 
You need to create another table that will hold only distinct codes. You can
add it to the same dataset or have in a different dataset. After populating
the big table, loop through it, detect new codes, and add them to that new
table.

Eliyahu
 
new table you mean datatable or an actualy table in the DB?
would you have a snippet on doing this?
 
I mean a datatable in a dataset, not in the DB. I do have a piece of code
doing this, but it is specific to the class infrastructure I am using and it
would take some time to make it understandable for you. Sorry.

Eliyahu
 
Back
Top