Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert multiple rows to db at one time

Status
Not open for further replies.

kaijanm

Programmer
May 14, 2003
102
US
I need to create an interface to post a batch of records to the database and I'm trying to figure out the best way to do this. Every example I can find is to insert one row at a time. I'm thinking a data set, but I'm not sure. The number of records to post at a time is variable. I'd like this to act similarly to how this works in access, so when you complete one row, another row shows up for entry. Does this make sense?

Anyone have any thoughts on the subject?

Thanks in advance!
Kimberly
 
The .NET way is to use a DataSet in conjunction with a DataAdapter.

See here for an example:


Basically you fill the DataSet with records, then call DataAdapter.Update() and the DataAdapter will use the InsertCommand (et al) that you define to update the DB.

[COLOR=blue gainsboro]
Get a FREE iPod by helping me get mine! Click my referrer link:

More about the company and deal:
[/color]
 
Ok, all the documentation I can find about datasets assumes that I have data to initially fill the datatables. In this case, I do not. I just want to create a data set and insert it all at the same time into the db. Is there a way to create the data tables without binding them to a table on the back end?

I feel like I'm missing something here.

TIA!
Kimberly
 
Basically you just don't initialize the DataSet/Table with a fill.

If you simply add rows to your DataTable and end up with a bunch of rows having the RowState automatically set to RowState.Added, then the DataAdapter will consider each row "new" and use the InsertCommand for each.

[COLOR=blue gainsboro]
Get a FREE iPod by helping me get mine! Click my referrer link:

More about the company and deal:
[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top