Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...

I try to import dat file into mysql database through using c#.how can i write code for this...
below is my .dat file format . i want to display data into column in datagrid

VB
5    ,000022,004050          ,000004,19.09.14,12341234
  4021,000100,SONU GANPAT YADA,1550  ,19.09.14,000100
  4068,000500,SANDIP BABAN AKH,9050  ,19.09.14,000500
  4119,001000,JEEVAN KAMALAKAR,41080 ,19.09.14,001000
  4139,000050,INDUBAI RAMCHAND,1400  ,19.09.14,000050
  4144,000100,SUREKHA SANJAY P,2900  ,19.09.14,000100
  4650,000100,YASHWANT GOVINDR,5300  ,19.09.14,000100
  4654,000050,SACHIN BALKRISHN,750   ,19.09.14,000050
  4656,000100,SITARAM LAXMAN G,3500  ,19.09.14,000100
  4659,000100,MAHESHKUMAR SHAR,2000  ,19.09.14,000100
  4623,001000,MEENA KISHOR KAM,43000 ,19.09.14,001000
  4626,000200,HUSSAIN . HASHAM,8000  ,19.09.14,000200
  4629,000200,SHABANA KAUSAR N,14800 ,19.09.14,000200
  4630,000100,GANESH K SUKALE ,3000  ,19.09.14,000100
  4632,000050,RAVINDRA LAXMAN ,3250  ,19.09.14,000050
  4633,000050,SAHIL HARISH YEO,3250  ,19.09.14,000050
  4634,000025,SAVITA ANIL YEOL,1700  ,19.09.14,000025
  4635,000025,ANIL LAXMAN YEWL,1700  ,19.09.14,000025
  4639,000050,NISHA SURESH NAI,2100  ,19.09.14,000050
  4640,000050,KUNAL SURESH NAI,2100  ,19.09.14,000050
  4641,000050,SANIKA SURESH NA,2100  ,19.09.14,000050
  4643,000100,SANJAY UTRESHWAR,6100  ,19.09.14,000100
  4644,000050,MANGALA LAXMAN K,3200  ,19.09.14,000050

Posted

1 solution

1. Create a DataTable with columns matching your dat structure.
The columns should be typed, e.g. string, int, DateTime etc.

2. Read the file line by line in a loop.

2a. Use String.Split to split each line into parts.
Use comma (,) as the separator.
Beware that this only works if commas are not allowed inside the "columns".

2b. Convert each part to the correct data type and create a new DataRow per line

2c. Add the DataRow to the DataTable.

3. Use the DataTable as the DataSource of the DataGridView.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900