Guest User

Guest User

  • Tech Writer
  • 357
  • 118.1k

A Textbox value broken down into individual values and persisted to Database, one per row.

May 11 2012 6:26 AM
Hi

I have a Textbox which holds a numeric value from 0-9999 to determine the Quantity of an item.

Rather than persisting a value of say 9999 to the Quantity column of the DB, I would like to iterate through each value and persist to the DB in seperate rows.

I was thinking of going down the lines of getting the quantity and storing in a local variable say totalQuantity.

int totalQuantity = 0;
totalQuantity += item.Quantity;

// result of totalQuantity is now 9999


for(int = 0; i < totalQuantity; i++)
{
        // Not sure how to get each [i] value and store? 
}

OrderDetail od = new OrderDetail();
od.Quantity = ?

// The ? should persist to Quantity DB field over and over until 9999 is reached.
(My DB fields cannot be Null so id have to use the same data for the other columns)

Im hoping there is an easier way than to create a new OrderDetail instance\object and set the Quantity property over and over, maybe something like:-

od.Quantity += totalQuantity;

Or maybe a list of numeric values which are then persisted back to the DB in one wrapped transaction!?

Thanks

Steven


Answers (10)