Writing datatable to database file, one record at a time in C#

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-04-07T06:39:56Z Indexed on 2010/04/07 6:43 UTC
Read the original article Hit count: 280

Filed under:
|
|

Hi! I want to write a C# program that will read a row from a datatable (named loadDT) and update a database file (named Forecasts.mdb). My datatable looks like this (each day's value is a number representing kilowatts usage forecast):

Hour  Day1  Day2  Day3  Day4  Day5  Day6  Day7
   1   519   520   524   498   501   476   451 

My database file looks like this:

Day   Hour  KWForecast
  1      1         519
  2      1         520
  3      1         524

... and so on.

Basically, I want to be able to read one row from the datatable, and then extrapolate that out to my database file, one record at a time. Each row from the datatable will result in seven records written to the database file. Any ideas on how to go about this? I can connect to my database, the connection string works, and I can update and delete from the database. I just can't wrap my head around how to do this one record at a time. Thanks in advance for any help and advice.

© Stack Overflow or respective owner

Related posts about c#

Related posts about datatable