Hi,
I need a FAST way to put the content of a file in a datatable (one record
for each line in the file).
I have a routine for it, but it takes me too much time (2-5 seconds for each
file) to put the lines in the datatable and do some actions. Does anybody
knows a faster method? The fact is: I actually only need the lines starting
with "0*" and "1*".
What I do now is:
- reading all the lines into a datatable
- I make a dataview from the datatable and apply a filter so I have only the
"0*" and "1*"-records left.
- I do some actions with the 0- and 1-records.
To make it faster I can do folowing things:
- only putting the 0-records and 1-records in the datatable (so I don't have
to apply a filter afterwards). But I'd prefer to put everything in it for
eventually future use of other records.
- I guess I lose most time with opening the file and reading every line in
it. Or am I wrong? Is there a way to do it much faster than I do? (see
routine at the end of the message)
Thanks in advance!!
Pieter
My lines-of-file-reading-into-datatable-routine:
Public Function ReadFileToDataT able(ByVal strDir As String, ByVal
strFile As String) As DataTable
Dim intMyFile As Integer = FreeFile()
Dim strLine As String
Dim myTable As DataTable = New DataTable("File Table")
Dim colID As DataColumn = New DataColumn("ID" ,
Type.GetType("S ystem.Int32"))
colID.AutoIncre ment = True
colID.AutoIncre mentSeed = 0
colID.AutoIncre mentStep = 1
myTable.Columns .Add(colID)
Dim colText As DataColumn = New DataColumn("Tex t",
Type.GetType("S ystem.String"))
myTable.Columns .Add(colText)
Dim NewRow As DataRow
Try
FileOpen(intMyF ile, MakePathFile(st rDir, strFile),
OpenMode.Input, OpenAccess.Read , OpenShare.Share d, -1)
'once the file is opened
'loop through every line and copy them to our
'variable
Do While Not EOF(intMyFile)
strLine = LineInput(intMy File)
NewRow = myTable.NewRow( )
NewRow("Text") = strLine
myTable.Rows.Ad d(NewRow)
Loop
myTable.AcceptC hanges()
Catch ex As Exception
MessageBox.Show (ex.Message & ex.StackTrace, "Exception" )
Finally
'sluiten van het bestand
FileClose(intMy File)
ReadFileToDataT able = myTable
End Try
End Function 2 1758
Hi Pieter,
The only thing I would add is (roughly typed not checked) Do While Not EOF(intMyFile) strLine = LineInput(intMy File)
if strLine.substri ng(0,2) = "*0" or strLine.substri ng(0,2) = "*1" then NewRow = myTable.NewRow( ) NewRow("Text") = strLine myTable.Rows.Ad d(NewRow)
end if Loop myTable.AcceptC hanges() '???? why are you doing updates later
that you want to keep track on?
I hope this helps a little bit.
Cor
Hm, thanks.
If I understand it good I don't need to use the "myTable.Accept Changes() "?
I thought it was needed to add the rows but I guess I'm wrong? hehe :-)
"Cor" <no*@non.com> wrote in message
news:O0******** ******@tk2msftn gp13.phx.gbl... Hi Pieter,
The only thing I would add is (roughly typed not checked) Do While Not EOF(intMyFile) strLine = LineInput(intMy File) if strLine.substri ng(0,2) = "*0" or strLine.substri ng(0,2) = "*1"
then NewRow = myTable.NewRow( ) NewRow("Text") = strLine myTable.Rows.Ad d(NewRow) end if Loop myTable.AcceptC hanges() '???? why are you doing updates
later that you want to keep track on?
I hope this helps a little bit.
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: aikwee |
last post by:
how, how do i clear the current content of a datagrid?
I am using datagrid to do a xml editor, so every time
i try to open anther file and load it to datagrid, it
actually append it in to previous contents...
please advice...
|
by: Amit Maheshwari |
last post by:
I need to read text file having data either comma seperated or tab seperated
or any custom seperator and convert into a DataSet in C# .
I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0 to read text file
but could not get the data in correct format.
All columns are not coming in dataset and rows are messing up.
Suggestions...
|
by: inpuarg |
last post by:
I have 2 datatables. They are identical. I want to compare them by
cell's content. They are all same.
But dt1 == dt2 or
dt1.GetHashCode() == dt2.GetHashCode() doesn 't work.
There are big amount of rows in theese datatables . So i don 't want
to enumerate each rows. This is not efficient and unacceptable for my
current application.
|
by: Sharath |
last post by:
"Inspired" by the huge success of our first two automation fast track
batches
We are forced to start third fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project...
|
by: Sharath |
last post by:
We are glad to inform you that
"Inspired" by the huge success of our first three automation fast
track
batches
We are forced to start fourth fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project
| |
by: Sharath |
last post by:
We are glad to inform you that
"Inspired" by the huge success of our first four automation fast
track
batches
We are forced to start fifth fast track automation batch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Course on Automation, QTP Basics and Advanced, Quality Center and
project
|
by: Ty |
last post by:
Hi all
Short version of my problem:
i have a Datagrid (Flexgrid from ComponentOne) with a Datatable as
source. I need to search a row in the datatable, using a primary key
column in the datatable, and then figure out wich row this currently
is in the Datagrid. This should probably be done using the currency
manager for speed reasons.
...
|
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== |
last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing
an .RLDC report in local report.
The columns for the report are essentially:
Month Item #1 Item#2 Item#3
I would like to add a checkbox or dropdown control to the .RLDC and have
Item #1, Item #2, or Item #3 display conditionally based on a checkbox being...
|
by: madankarmukta |
last post by:
Hi,
Objectives is to write the DataTable content to the text file in the format
Col1 | Col2 | Col3
------|-------|---------
Val11 | Val21 | Val31
Val12 | Val22 | Val32
Val13 | Val23 | Val33
|
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. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |