Solved

.Dat file to DataGridView1 VB.net

Posted on 2011-09-25
9
858 Views
Last Modified: 2012-05-12
Hello all

I'm working on a project where i need to import a .dat file into a DataGridView1 VB.Net.

Since there is no column in a .dat file, just text, and that in a DataGridView, there's columns, i need to import the .dat file, all separated in diffrent column based on  specific criterias.

The dat file row will always start with the letter "H" or the letter "D".

To be more specific, the first row will start with "H" and the next row, will start with "D"

Here are the criteria based on the .dat file in attachement:

'Row starting with the letter H

The 1stLetter "H' only must go in the first grid column.

The 2nd letter, "M" must go alone in grid column 2.

The 3rd digit "1" will go in column 3.

After, it will jump to the the field 15 of the .dat file to field 27. What's between field 15 to 26 will go in Grid column 4 (Trim). In that example from the flat file, i will have the text:REG_ROSS


In Field 27 only "5" will go in Grid column 5.  etc...


For Row starting with letter D


The 1stLetter "D' only must go in the first grid column.

The 2nd letter, "M" must go alone in grid column 2.

The 3rd digit "1" will go in column 3. etc.....


If i'm able to start with these cople of example, i will be able to continu with the rest of all the fields in the .dat file.


I need to TRIM the data, not to have empty spaces at the begining and after the text, transferes in the grid.

How can i do this, using the OpenFileDialog1 to select my .dat file i need to import?

Thanks again for your help.


*** For the .dat file, i was not able to attache it. So i have have changed it to a .doc. Just remove the .doc to the file name and it will transfer into a .dat file





.dat-file-image.jpg
tl.02110625153156.doc
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 5

Expert Comment

by:bitref
ID: 36596414
You may read the File using StreamReader and fill its contents in a DataTable object. After filling the DataTable, use it as the DataSource for the DataGridView.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36596461
Hello bitref

What is a StreamReader?

Is that a function in VB.Net?

I will google it also.

0
 
LVL 5

Accepted Solution

by:
bitref earned 500 total points
ID: 36597111
http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx#Y145

StreamReader is a class that can be used to read a stream of characters from a text file.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Wilder1626
ID: 36600564
ok, i will read that and i will let you know.

This is new for me.

Thanks
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36815781
Wilder1626 made any progress on this yet?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36818425
Actually, since I'm new in VB.net, i'm in lots of reading about this.

For now, i don't know how to use this to be able to populate my grid.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36818533
OK. Goodluck!
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 36894995
Thanks
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 37164126
Thanks for the link.

Now it work.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question