•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,801 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 3640 | Replies: 0
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hi All,
First off, thanks in advance for your time!
I'm a VB newbie, and I'm struggling with my first app.
The scenario: I'm trying to manipulate a tab-delimited text file based on the contents of a MS Access table.
My Approach: I'm at the point where I've imported the text file and the MS Access table into separate datatables.
My Question(s): I need to update the text file datatable based on values in the MS Access datatable, but I'm not sure how to progress. I can't use a relationship, because the text file contains both header and line data (the header data breaks the parent child relationship). What would the most sensible approach be from here?
Should I try :
A) split the text file into header and line datatables?
B) Should I loop through the text file looking for line data and then loop through the MS Access datatable looking for a match?
C) taking a VB.NET course?
Any pointers would be much appreciated. Also, critique of my entire approach would be good - - is there a better/easier way to achieve my goal?
I've attached a sample of my text file, and a .doc of my MS Access table.
Heres my relevant code (sorry its messy):
Thanks for your help!
Casey.
First off, thanks in advance for your time!
I'm a VB newbie, and I'm struggling with my first app.
The scenario: I'm trying to manipulate a tab-delimited text file based on the contents of a MS Access table.
My Approach: I'm at the point where I've imported the text file and the MS Access table into separate datatables.
My Question(s): I need to update the text file datatable based on values in the MS Access datatable, but I'm not sure how to progress. I can't use a relationship, because the text file contains both header and line data (the header data breaks the parent child relationship). What would the most sensible approach be from here?
Should I try :
A) split the text file into header and line datatables?
B) Should I loop through the text file looking for line data and then loop through the MS Access datatable looking for a match?
C) taking a VB.NET course?

Any pointers would be much appreciated. Also, critique of my entire approach would be good - - is there a better/easier way to achieve my goal?
I've attached a sample of my text file, and a .doc of my MS Access table.
Heres my relevant code (sorry its messy):
vb Syntax (Toggle Plain Text)
Private Function loadTheLookupTable() '1) Create a CONNECTION Dim cnConnection As New OleDb.OleDbConnection '2) Set the connection cnConnection.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\work\blahblah\CBA_SAP_AccountsLookup.mdb" '3) Create a DATASET '4) Create a DATA ADAPTOR Dim daDataAdaptor As New OleDb.OleDbDataAdapter daDataAdaptor = New OleDb.OleDbDataAdapter("select * from qryGroupedLookup", cnConnection) '5) Fill a DATASET using the DATA APAPTOR daDataAdaptor.Fill(dsLookupData, "CBA_SAP_Lookup") 'Open the connection 'Close the connection cnConnection.Close() End Function Private Function loadTheTextFile() Dim file As String = "C:\work\blahblah.txt" Dim cmdtxt As String = ("SELECT * FROM " & file & "") '1) Create a CONNECTION Dim cnConnection As New Odbc.OdbcConnection '2) Set the connection cnConnection.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=c:\work\;Extensions=asc,csv,tab,txt;" '4) Create a DATA ADAPTOR Dim daDataAdaptor As New Odbc.OdbcDataAdapter(cmdtxt, cnConnection) ''daDataAdaptor = New Odbc.OdbcCommand(cmdtxt, cnConnection) ' Create a DataTable. Dim myTable As DataTable = New DataTable("TextFile") ' Create a DataColumn and set various properties. Dim myColumn As DataColumn = New DataColumn myColumn.DataType = System.Type.GetType("System.String") myColumn.AllowDBNull = False myColumn.Caption = "CbaAccount" myColumn.ColumnName = "CbaAccount" myColumn.DefaultValue = "" ' Add the column to the table. myTable.Columns.Add(myColumn) '5) Fill a DATASET using the DATA APAPTOR daDataAdaptor.Fill(dsLookupData, "TextFile") Dim myRow As DataRow Dim col As DataColumn Dim count As Integer = 0 Dim currentRow As String Dim IsNull As Boolean For Each col In dsLookupData.Tables("TextFile").Columns IsNull = IsDBNull(dsLookupData.Tables("TextFile").Rows(count).Item(0)) 'Test for blank lines in the text file If IsDBNull(dsLookupData.Tables("TextFile").Rows(count).Item(0)) = False Then myRow = myTable.NewRow() currentRow = dsLookupData.Tables("TextFile").Rows(count).Item(0) myRow("CbaAccount") = currentRow ' Be sure to add the new row to the DataRowCollection. myTable.Rows.Add(myRow) 'update the rows contents dsLookupData.Tables("TextFile").Rows(count).Item(0) = dsLookupData.Tables("TextFile").Rows(count).Item(0).Substring(0, 2) 'increment the row count count = count + 1 Else 'increment the row count count = count + 1 End If Next 'Rename the column to a meaningful name instead of the arbitary first line value dsLookupData.Tables("TextFile").Columns.Item(0).ColumnName = "CbaAcc" End Function
Thanks for your help!
Casey.
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: Searching for name in txt file.
- Next Thread: Need help with this game i've created


Linear Mode