Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have this "Typed Dataset"
where its columns and data types are:

Field Name Data Type
primary_key int
emp_name varchar
emp_id varchar
department varchar
position varchar
date date
time_in datetime
break_out datetime
break_in datetime
time_out datetime

and in some way i would like to populate this dataset using this kind of records from a .txt fil

VB
37,PETER L PARKER,1,LABORATORY,STAFF,5/1/2012,5/1/2012 08:00:15,5/1/2012 12:00:34,5/1/2012 13:30:55,5/1/2012 17:30:05
38,PETER L PARKER,1,LABORATORY,STAFF,5/2/2012,5/2/2012 08:20:24,5/2/2012 12:00:37,5/2/2012 13:01:21,5/2/2012 17:00:48
39,PETER L PARKER,1,LABORATORY,STAFF,5/3/2012,5/3/2012 08:30:01,,,5/3/2012 17:30:13



however during my tries it still doesn't work

I actually tried those codes @ http://social.msdn.microsoft.com/Forums/pl-PL/adodotnetdataproviders/thread/952ab4ca-97d4-4cc8-9db8-d5d562161461[^]
But still no success at all.

hope someone could share some knowledge and wisdom

Copied from "solution"
It means that i actually do not get what i want to achieve.
Honestly i am not that good in vb.net but i am eager to learn so maybe someone could help me again
Posted
Updated 24-Jul-12 9:49am
v2
Comments
[no name] 24-Jul-12 15:21pm    
What does "still doesn't work" and "no success at all" mean?
Trak4Net 24-Jul-12 15:31pm    
You will be way better off using streamreader and some regular expressions to parse out the columns. If you have control of the source data and can be sure you will never have a comma within your data value then you could skip the regex and just do a string.split.
Once upon a time I went down the road of the Oledbconnection and I had nothing but issues when using on different systems, different data files. I developed my own flat file reader that has all of the functionality I needed using streamreader and regex.
[no name] 24-Jul-12 15:58pm    
So, after your update where you stated exactly what the problem is, you did not bother answering the quesiton of "what is your problem"? Telling us "it don't work" or "I am not getting what I want" does not tell us anything. We cannot read your mind. Open the file, parse the text and stick the text in the dataset. None of these operations are particularly difficult. Search for "opening a file", "reading text file" then "parsing text". That's how you learn....
Sergey Alexandrovich Kryukov 24-Jul-12 16:19pm    
This is not a question, and your "doesn't work" is not informative. You cannot get help this way.

Besides, why did you reply to the comment by Wes with "solution"? It is not; I had to remove it. Add your comments to existing post if you want.
--SA

1 solution

Not sure if this is what you need but to read a basic text file is an exercise in looping. This is some simple code I started using early in my coding career, it is simple but not robust.

This is the main bit of code, you send it a datatable that you want the text file information put into and the name of the file you want to read. It will place each semicolon separated string into a column of the datatable. Important: the datatable sent must have at least 1 column for each segment in the file.
VB
Private Sub ReadFile(sTable As DataTable, sFileName As String)
        Dim line As String

        ' Read the file line by line.
        Dim file As New System.IO.StreamReader(Application.StartupPath + "\" + sFileName)
        line = file.ReadLine()
        While (line) IsNot Nothing
            Dim tmpline As String = line
            Dim tmpStrings As String()

            Dim tmpRow As DataRow = sTable.NewRow()

            Dim i As Integer = 0
            While tmpline.Length > 0
                tmpStrings = NextLine(tmpline)
                tmpline = tmpStrings(1)
                tmpRow(i) = tmpStrings(0)
                i += 1
            End While

            sTable.Rows.Add(tmpRow)
            line = file.ReadLine()
        End While

        file.Close()
    End Sub


And here is the NextLine Function:
VB
Private Function NextLine(line As String) As String()
	Dim tmpString As String() = New String(1) {}

	tmpString(0) = line.Substring(0, line.IndexOf(";"))
	tmpString(1) = line.Substring(line.IndexOf(";") + 1, line.Length -     (line.IndexOf(";") + 1))

	Return tmpString
End Function
 
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