I am new to Visual Basic, my preferred languages is C or C++. I am trying to load a local database with data that I am reading from a delimited flat file. I have created the database tables and added all primary keys and a set of foreign keys. I have also created a Dataset for same. Now I was expecting that I could load the data set from the data that I am parsing from the flat file. Houever when I attempt to enter data into the dataset I can't seem to access an individual field The code line used looks like
ARDataSet.HDDat aTable.?? = GetToken(line, Next, '|')
What I wanted to have in place of the ?? is a field, in this case RecType which is a char(2). The GetToken routine is one that I wrote which works fine, it returns a string. I don't know what's missing, or if I am totally barking up the wrong tree.
Should I be using LINQ? and if so, could someone point me in the direction of an example which loads a table from a delimited flat file?
OldieNubie
3 3178 sashi 1,754
Recognized Expert Top Contributor
HI OldieNubie,
Kindly post your code, will try to debug it. Take care.
Sashi,
Thank you for your reply, Here;s the detail:
The following code is the tokenizer which works.
the first call passes NewItem as True, followed by the string to be tokenized, followed by the delimiter All repeat calls (until the end of string) pass NewItem as false along with two empty strings. As soon as I learn how to overload, I will not require any parameters after the first call, unless a new string is being sent. I also realize that I will have to handle an empty string exception. - Private Function GetToken(ByVal NewItem As Boolean, ByVal NewString As String, ByVal Delimeter As Char) As String
-
Dim builder As New System.Text.StringBuilder
-
Static Dim HoldString As String
-
Static Dim LastPos As Integer
-
Static Dim Delim As Char
-
Dim ThisChar As Char
-
Const Lf As String = ControlChars.Lf
-
Dim Token As String
-
-
If NewItem Then
-
HoldString = NewString
-
Delim = Delimeter
-
LastPos = 0
-
End If
-
-
If (LastPos > 0) Then
-
LastPos = LastPos + 1
-
End If
-
-
ThisChar = HoldString.Substring(LastPos, 1)
-
While (ThisChar <> Delim) And (ThisChar <> Lf)
-
builder.Append(HoldString.Substring(LastPos, 1))
-
LastPos = LastPos + 1
-
ThisChar = HoldString.Substring(LastPos, 1)
-
End While
-
-
If (ThisChar) = Lf Then
-
Token = "GoodBye"
-
Else
-
Token = builder.ToString
-
End If
-
-
Return Token
-
End Function
I did create a structure to check out the tokenizer as follows; this is essentially what the HD table in the DataSet looks like. - Public Structure HeadRec
-
Public RecType As Char()
-
Public SysId As Integer
-
Public UlsFileNum As Char()
-
Public EbfNum As Char()
-
Public CallSign As Char()
-
Public LicenseStatus As Char
-
Public RadioServiceCd As Char()
-
Public GrantDt As Date
-
Public ExpiredDt As Date
-
Public CancellationDt As Date
-
Public EligibilityRuleNum As Date
-
Public Reserved1 As Char
-
Public Alien As Char
-
Public AlienGovernment As Char
-
Public AlienCorporation As Char
-
Public AlienOfficer As Char
-
Public AlienControl As Char
-
Public Revoked As Char
-
Public Convicted As Char
-
Public Adjudged As Char
-
Public Reserved2 As Char
-
Public CommonCarrier As Char
-
Public NonCommonCarrier As Char
-
Public PrivateComm As Char
-
Public Fixed As Char
-
Public Mobile As Char
-
Public RadioLocation As Char
-
Public Satellite As Char
-
Public DevelOrSTAOrDemo As Char
-
Public InterconnectedService As Char
-
Public CertifierFirstName As Char()
-
Public CertifierMi As Char
-
Public CertifierLastName As Char()
-
Public CertifierSuffux As Char()
-
Public CertifierTitle As Char()
-
Public Female As Char
-
Public AfericanAmerican As Char
-
Public NativeAmerican As Char
-
Public Hawaiian As Char
-
Public Asian As Char
-
Public White As Char
-
Public Hispanic As Char
-
Public EffectiveDt As Date
-
Public LastActionDt As Date
-
Public AuctionId As Integer
-
Public BroadcastSrvcRegulatoryStatus As Char
-
Public BandManagerRegulatoyStatus As Char
-
Public BroadcastSrvcTypeOfRadioSrvc As Char
-
Public AlienRuling As Char
-
Public LicenseNameChange As Char
-
End Structure
-
The following code is where I used the structure (which I wanted to eliminate). I was expecting that I could insert the data directly into the dataset, then remove the structure from the code altogether. What I am receiving is a Readonly error (Commented out ARDataSet.HD.Re cTypeColumn = GetToken(True, line, "|") - Private Sub LoadHDtable()
-
Dim ARDataSet As AmateurRadioDataSet
-
Dim HeaderRec As HeadRec
-
Dim SourcePos As Integer = 0
-
Dim DestPos As Integer = 0
-
Dim InFileName As String = DestinationDirectory + "HD.dat"
-
Dim temp As String = ""
-
Dim Token As String
-
Dim line As String
-
' Create an instance of StreamReader to read from the file.
-
Dim InFile As System.IO.StreamReader = New System.IO.StreamReader(InFileName)
-
-
Try
-
' Read and display the lines from the file until the end
-
' of the file is reached.
-
Do
-
line = ""
-
line = InFile.ReadLine()
-
' AmateurRadioDataSet.HDDataTable. = GetToken(True, line, "|")
-
HeaderRec.RecType = GetToken(True, line, "|")
-
' want to replace above with something like
-
' ARDataSet.HD.RecTypeColumn = GetToken(True, line, "|")
-
' and so on for all columns I get a 'Column is readonly error
-
Token = GetToken(False, "", "")
-
HeaderRec.SysId = System.Convert.ToInt32(Token)
-
HeaderRec.UlsFileNum = GetToken(False, "", "")
-
HeaderRec.EbfNum = GetToken(False, "", "")
-
HeaderRec.CallSign = GetToken(False, "", "")
-
HeaderRec.LicenseStatus = GetToken(False, "", "")
-
HeaderRec.RadioServiceCd = GetToken(False, "", "")
-
HeaderRec.GrantDt = GetToken(False, "", "")
-
HeaderRec.ExpiredDt = GetToken(False, "", "")
-
HeaderRec.CancellationDt = GetToken(False, "", "")
-
HeaderRec.EligibilityRuleNum = GetToken(False, "", "")
-
HeaderRec.Reserved1 = GetToken(False, "", "")
-
HeaderRec.Alien = GetToken(False, "", "")
-
HeaderRec.AlienGovernment = GetToken(False, "", "")
-
HeaderRec.AlienCorporation = GetToken(False, "", "")
-
HeaderRec.AlienOfficer = GetToken(False, "", "")
-
HeaderRec.AlienControl = GetToken(False, "", "")
-
HeaderRec.Revoked = GetToken(False, "", "")
-
HeaderRec.Convicted = GetToken(False, "", "")
-
HeaderRec.Adjudged = GetToken(False, "", "")
-
HeaderRec.Reserved2 = GetToken(False, "", "")
-
HeaderRec.CommonCarrier = GetToken(False, "", "")
-
HeaderRec.NonCommonCarrier = GetToken(False, "", "")
-
HeaderRec.PrivateComm = GetToken(False, "", "")
-
HeaderRec.Fixed = GetToken(False, "", "")
-
HeaderRec.Mobile = GetToken(False, "", "")
-
HeaderRec.RadioLocation = GetToken(False, "", "")
-
HeaderRec.Satellite = GetToken(False, "", "")
-
HeaderRec.DevelOrSTAOrDemo = GetToken(False, "", "")
-
HeaderRec.InterconnectedService = GetToken(False, "", "")
-
HeaderRec.CertifierFirstName = GetToken(False, "", "")
-
HeaderRec.CertifierMi = GetToken(False, "", "")
-
HeaderRec.CertifierLastName = GetToken(False, "", "")
-
HeaderRec.CertifierSuffux = GetToken(False, "", "")
-
HeaderRec.CertifierTitle = GetToken(False, "", "")
-
HeaderRec.Female = GetToken(False, "", "")
-
HeaderRec.AfericanAmerican = GetToken(False, "", "")
-
HeaderRec.NativeAmerican = GetToken(False, "", "")
-
HeaderRec.Hawaiian = GetToken(False, "", "")
-
HeaderRec.Asian = GetToken(False, "", "")
-
HeaderRec.White = GetToken(False, "", "")
-
HeaderRec.Hispanic = GetToken(False, "", "")
-
HeaderRec.EffectiveDt = GetToken(False, "", "")
-
HeaderRec.LastActionDt = GetToken(False, "", "")
-
HeaderRec.AuctionId = GetToken(False, "", "")
-
HeaderRec.BroadcastSrvcRegulatoryStatus = GetToken(False, "", "")
-
HeaderRec.BandManagerRegulatoyStatus = GetToken(False, "", "")
-
HeaderRec.BroadcastSrvcTypeOfRadioSrvc = GetToken(False, "", "")
-
HeaderRec.AlienRuling = GetToken(False, "", "")
-
HeaderRec.LicenseNameChange = GetToken(False, "", "")
-
' To do Commit dataset into database table
-
Loop Until line Is Nothing
-
InFile.Close()
-
Catch ex As Exception
-
' Let the user know what went wrong.
-
Console.WriteLine("The file could not be read:")
-
Console.WriteLine(ex.Message)
-
End Try
-
End Sub
-
If you need to see the database layout, I'll have to figure out which .xml file it's in and post that there are many tables.
Thanks in advance
Larry
Sashi,
If you need a copy of the the data that I am using, you can download a copy with the following: The HD file is the one used in my example code - Dim CurrentDirectory As String = Application.StartupPath() + "\"
-
Dim DestinationDirectory As String = CurrentDirectory + "DataFiles\"
-
Dim FileName As String = "l_amat.zip"
-
Private Sub GetFCCDataFile()
-
Dim remoteUri As String = "http://wireless.fcc.gov/uls/data/complete/"
-
Dim Downloadfile As String = remoteUri + FileName
-
Dim myWebClient As New System.Net.WebClient()
-
-
Try
-
' Determine whether the directory already exists.
-
' Create the directory.if it's not there
-
System.IO.Directory.CreateDirectory(DestinationDirectory)
-
' Move to data directory
-
System.IO.Directory.SetCurrentDirectory(DestinationDirectory)
-
' Download the file
-
myWebClient.DownloadFile(Downloadfile, FileName)
-
' Restore original directory
-
System.IO.Directory.SetCurrentDirectory(CurrentDirectory)
-
Catch ex As Exception
-
Console.WriteLine("Unable to download file: {0}", ex.ToString())
-
End Try
-
End Sub
Larry
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: siliconmike |
last post by:
How do I synchronize MySQL table data of my home PC with latest data
from a remote server ?
My home PC is on a very slow internet connection, so implementing
replication will cause long time read lock on remote server, which is
not desirable.
What are the tools for manual sync of tables ?
I'm running FreeBSD on my home PC.
|
by: amorphous999 |
last post by:
I want to use DTS to load from a flat file. But I can't be sure when
the flat file will arrive. I would like the job to check every 10
minutes or so for a couple of hours. If the file is present, then load
the file and rename it so that it doesn't get overwritten. Any
suggestions?
TIA,
amorphous999
|
by: Jonathan Buckland |
last post by:
Can someone give me an example how to append data without having to
load the complete XML file.
Is this possible?
Jonathan
|
by: Paul M. |
last post by:
Hi,
Are there any examples of building a simple local database with
C# Express 2005?
TIA
|
by: vunet.us |
last post by:
Hi,
I would like to use flat file data storage instead of database. Since I
am new to it, I am wondering:
What text file extension is a safe one to store my data online and how
cost- and time-effective is this method (flat file data storage).
Anyone can share thoughts? Thanks
| |
by: ircmaxell |
last post by:
Ok, I have a program that reads the contents of a file (1 line, 5 '|'
seperated items). Every so often (between twice a day, and 200 times a
day), it rewrites the contents of that file. I also do a few database
update queries whenever the file is written. I only open up the
database connector if I need to update the database. The script itself
runs every 30 seconds. My question, is that is it faster and more
efficient to read the file...
|
by: Fordraiders |
last post by:
vb.net 2003
Office 2003
What I have:
C:\TestData\Input.txt
Text File Pipe Delimited : 4 columns Of data
example:
00001|NO BRAND NAME ASSIGNED|6DU27|M3-.5 X 6 FLAT HD SOCKET CAP SCREW,
CL10.9, ALLOY STEEL
00002|NO BRAND NAME ASSIGNED|6DU28|M3-.5 X 8 FLAT HD SOCKET CAP SCREW,
|
by: felciano |
last post by:
Hello --
Is there a convention, library or Pythonic idiom for performing
lightweight relational operations on flatfiles? I frequently find
myself writing code to do simple SQL-like operations between flat
files, such as appending columns from one file to another, linked
through a common id. For example, take a list of addresses and append
a 'district' field by looking up a congressional district from a
second file that maps zip codes to...
|
by: techquest |
last post by:
Hi,
I want to connect into oracle database and export the table data into a flat file using UNIX shell scripts. I cant use other GUI tools to do this, as the dataload will be in millions. hence if i try to export from toad/sqlplus its hanging. And also i need to some validation using UNIX. So please give me some tip to write a script which does this operation.
Req:
1) Connect oracle
2) Select * from employee
3) Write into some flat...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |