-2

I want to read some data from a .csv file and store them in a DB2 table using C#. I am new to both C# and DB2. I just have two values separated by commas in each line of the .csv file.

Could someone provide me some link or sample code for my purpose?

I can insert into a DB2 table using hard-coded values. But I am not able to insert in a loop using variables.

Any kind of help would be appreciated.

Thanks in advance.

1 Answers1

0

For your first problem, reading from a .csv file, here's a link that shows how to read from a .CSV file. This example will store what it reads from your .csv file into a collection (a string array) called Fields. You could easily store it in a data table. That way, you can step through each row of the data table and write it out to your DB2 database.

Now, the second part of your problem, writing to a DB2 table, depends on what technology you'd like to use. LINQ, Entity Framework, T-SQL, etc. You need to read up on these to figure out how to take your collection of data and write it out to a DB2 database. There are tons of tutorials online and quite a few good ones on YouTube.

What you're attempting to do is easy enough, but only with understanding each part of the problem, with regards to how to leverage C# to solve the problem. Please try to go one step-at-a-time. Learning C# can be daunting if you try to rush it. Take your problem, make a list of each step that you want to accomplish, and go from there.

Community
  • 1
  • 1
Kevin
  • 4,798
  • 19
  • 73
  • 120