How can I do that?

  • Thread starter Thread starter Diego F.
  • Start date Start date
D

Diego F.

Hi. I need to map items from a DataSet to a SQL table.
The problem is that in the DataSet I can have the same item repeted, but in
the table, I have a field "quantity" to avoid that. So what I need is a
structure where I get each item and the number of repetitions.

In the DataSet, I have one table and I only need to use one column, and the
items are integers, so the idea is passing from:

100 102 100 103 to
100 (2) 102 (1) 103 (1) or something like that.

I don't know if I can get something with the DataSet Select method. I passed
the column to an ArrayList, but I don't know if that simplifyes something.

Can you help me?

Regards,

Diego F.
 
It would probably be better (easier or more efficient) to have the SQL
Server worry about and handle the repetitions, then all you need is for for
code to move through each value and fire it to the SQL Server (which would
be incredibly fast and easy to implement).

Basically on the SQL Server, you would write a stored procedure that takes
the integer input and checks if it already exists, if so it would increment
the quantity of that row. Otherwise it would insert a brand new row for that
integer.
Your code could then simply call the stored procedure for each integer in
the dataset.

Hope this helps.

Br,

Mark.
 
Diego,

This is like a crosstab somewhat, with some calculated values. The
Select method will not be able to help you, as it doesn't allow for the
selection of distinct items.

What I would do is use a DataView and sort the column. Then, cycle
through all the rows, maintaining a count of each unique value (it would be
easy enough to implement change detection).

Hope this helps.
 
Back
Top