I just started learning C# and I’ve made a few simple applications. The application I’m working on now is an application that reads and enters data to a (Access) database. I connected successfully to the database and I can enter data to it. Now the problem.
I have a csv file with data (orders). I want to load these orders to the database. The csv file looks like:
Order 1: 2 cakes,01-01-2013,chocolate,Jan|Order 2: 5 cakes,01-08-2013,vanilla,Piet|
As you can see it is ordered by (same as in my database table): [Order #], [Amount], [Date], [KindOfCake],[Buyer] and the new order comes right after the halfpipe (|).
This is what I've got:
String[] orders1= File.ReadAllText(@"c:\\orders.csv").Split('|');
for (int i = 0; i < orders1.Length; i++)
{
textBox1.AppendText(orders[i] + Environment.NewLine);
}
But this will load all the text into one textBox. I'm thinking about loading the data in the csv (seperated with a ',') to different textBoxes and then loading the values of the textBoxes to a database. But that is not the best way I'm guessing.
What is the best way for me to load all data in the CSV to my database?
Thank you very much for the tips.