-5

I am trying to import a .csv file into database in C# windows application without header row.

Thank you to all.

My .csv file format is

001,0000002226,01,2011/03/27,07:07,        
001,0000009392,01,2011/03/27,07:12,        
001,0000002220,01,2011/03/27,07:17,        
001,0000002121,01,2011/03/27,07:19,        
001,0000002205,01,2011/03/27,07:20,        
001,0000002125,01,2011/03/27,07:25,        
001,0000002270,01,2011/03/27,07:30,        
001,0000009050,03,2011/03/27,07:34,        
001,0000002251,03,2011/03/27,07:34,        
001,0000002141,01,2011/03/27,07:36,        
001,0000002236,01,2011/03/27,07:42,        
001,0000002169,01,2011/03/27,07:43,        
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
haider
  • 1
  • 1
  • 2
  • Could you provide a [mcve] that outlines what you've tried please? – Stephen Ross Jun 09 '16 at 11:05
  • First approach (completely handwritten): Open file, read line by line, on every line: split into your values, use SqlCommand to execute an insert (and PLEASE use the parametrized Version). Quit simple tasks. If you stuck with one part, ask that part again. And if you stuck on another part, ask again. – nabuchodonossor Jun 09 '16 at 14:26
  • Second method: Use the "Build In" TextFieldParser (although in Microsoft.VisualBasic.FileIO Namespace, you CAN use it from C#). – nabuchodonossor Jun 09 '16 at 14:29

1 Answers1

1

Don't reinvent the wheel, use a 3rd party like FileHelpers; then you can use attributes to ignore the first row, for example.

Community
  • 1
  • 1
Alexandru Marculescu
  • 5,569
  • 6
  • 34
  • 50