none
populating a Dataset with text from a text file RRS feed

  • Question

  • Hey everyone!  I'm looking for help with bring text in from various text files and populating a dataset in order to fill a MS access database. 

    here is a sample of my text files (date, update person, revision, AS400 revision, part number, respectively):

    11/11/06

    CW

    A

    A

    12345

     

     

    Now i can put them into textboxes and then import them into the dataset.  Tho i have searched and I can not find any information on how to bring text from text files into a dataset for eventual insertion into a database (already created, tho empty). 

     

     

     

    If anyone has anything that could help me, please reply!!!!!!!

     

    Thank you in advance!

     

    Monday, September 10, 2007 6:47 PM

All replies

  • Hi,

     

    No worries. You'll have code that parses the text file and populates textboxes from that file. Well instead of populating the textboxes you'll want to add a new row to a table within your dataset. Once you fill your dataset you can then look to fill the database. You will need to create a table in your dataset to hold the data, maybe you use the designer or maybe you create the columns through code. Regardless I'll assume you have this table in your dataset.

     

    So what your looking for is a couple of steps.

     

    0. Build datatable (either standalone of part of a dataset)

    1. For each text file

    2.     Read the data from the file and place into variables

    3.     Create a new row in the datasets table

    4.     Fill the row with the data read from the files

    5.     Add the new row to the table

    6. Next File

    7. Update database table with data in dataset table.

     

    Thats your general steps, and here is some information on how to go about doing them

     

    http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.6.shtml

     

    http://www.microsoft.com/mspress/books/sampchap/5199a.aspx

     

    Give it a go and post again if you have any problems

     

    Tuesday, September 11, 2007 11:33 AM
  • I looked for something similar for some time but ended up writing a custom Text to dataset importer which can parse a line with a given delimiter.

     

    Tuesday, September 11, 2007 1:29 PM
  • The links you provided were very helpful.  But I'm still having issues with filling the dataset or rather viewing it.

     

    I created the the dataset and a data table (below)

     

    Dim ds As RIDXXXDS 'create dataset

    Dim dt As New Data.DataTable("RIDXXXDS") 'create data table in dataset

     

    'add columns to data table

    dt.Columns.Add("Update", GetType(Date))

    dt.Columns.Add("Updater", GetType(String))

    dt.Columns.Add("Revision", GetType(String))

    dt.Columns.Add("ASRevision", GetType(String))

    dt.Columns.Add("Part", GetType(String))

    dt.Columns.Add("Description", GetType(String))

     

    'I also created the new row variable

    Dim row As Data.DataRow = dt.NewRow()

     

    'loop for each line (different variable on each line)

     

    Select Case linecount

    Case 1

    update = aline

    row.Item("Update") = update

    Case 2

    updater = aline

    row("Updater") = updater

    Case 3

    revision = aline

    row("Revision") = revision

    Case 4

    ASRev = aline

    row("ASRevision") = ASRev

    Case 5

    part = aline

    row("Part") = part

    Case 6

    description = aline

    row("Description") = description

    End Select

     

    dt.Rows.Add(row) 'new row

    DataGrid1.DataSource = Ridxxxds1.Tables(0)

     

    I can set the valueof aline to the respective variable (ie update = aline). I can not see the values in the datatable.  Am I doing something wrong in setting up the datagrid on the form?  Any help wouldbe more that gracious as my project time is short!!!

     

    Thanks in advance!!

     

    Tuesday, September 18, 2007 8:08 PM
  • Hi,

     

    Looking at the code there I see a couple of things.

     

    How your creating the datatable below is spot on...

    Dim dt As New Data.DataTable("RIDXXXDS") 'create data table in dataset

     

    'add columns to data table

    dt.Columns.Add("Update", GetType(Date))

    dt.Columns.Add("Updater", GetType(String))

    dt.Columns.Add("Revision", GetType(String))

    dt.Columns.Add("ASRevision", GetType(String))

    dt.Columns.Add("Part", GetType(String))

    dt.Columns.Add("Description", GetType(String))

     

    But your not adding it to the dataset, it's a standalone table... that should do it

     

    Dim ds As New RIDXXXDS 'create dataset

    ds.Tables.Add(dt)

     

    You also want to move the line that creates the row, and the line that adds the row to the table within your loop

     

    'loop for each line (different variable on each line)

    'I also created the new row variable

    Dim row As Data.DataRow = dt.NewRow()

    Select Case linecount

    Case 1

    update = aline

    row.Item("Update") = update

    Case 2

    updater = aline

    row("Updater") = updater

    Case 3

    revision = aline

    row("Revision") = revision

    Case 4

    ASRev = aline

    row("ASRevision") = ASRev

    Case 5

    part = aline

    row("Part") = part

    Case 6

    description = aline

    row("Description") = description

    End Select

    dt.Rows.Add(row) 'new row

     

    'end of loop here

     

    Then you bind it to your grid....

     

    DataGrid1.DataSource = ds.Tables(0)

     

    Try these changes and if you still don't get it working post again and I'll have a look.

    Thursday, September 20, 2007 11:15 AM
  • Hey,

     

    Thanks for the update.  I haven't checked this out in a while due to recently finding a job.  I left my internship about 2 weeks ago and found a full-time job.  I'm hoping to be able to look at the code this weekend (as I still kind of owe a finished working program to my internship company).   

     

    I always thought I had it but it never worked if this works I'm going to celebrate.  lol  I'll most definitely let you know if this works.

     

    Thanks for all the help.  I means a ton!!!!!!!!

     

    Thursday, October 4, 2007 4:08 PM