473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please Help with strange behavior loading a DataTable

I wrote the following code to load a DataTable with a CSV file. My
problem is: If I include the line "MyTable.Clear()" before I start
loading the Table, I'm presented with the 2nd line of my CSV file
presented twice (rows 0 and 1 of the table) and the 1st line of the CSV
file is missing. If I remove the "Clear" statement, then all my data is
there, but there's a blank row at Row 0.

Help!?!?!?

Thanks!

--------- Begin Code -------------

Private Sub LoadFile2Grid(ByVal fileName As String)
Dim sr As StreamReader = New StreamReader(fileName) 'Opens the
file for reading
Dim strLine As String 'Holds each
line of the file as it reads
Dim MyArray() As String 'Holds each
delimited sub-string from the line
Dim i As Integer 'Counter for
loops
Dim myRow As DataRow
myTable.Clear() 'Empty out
the table before loading the file
strLine = sr.ReadLine 'Reads in
the first line of the file
While Not strLine Is Nothing
MyArray = Split(strLine, ",") 'Splits line
up into an array of fields
'If not enough columns for the next line, add as many as we
need
If myTable.Columns.Count < MyArray.GetUpperBound(0) + 1 Then
For i = myTable.Columns.Count To
MyArray.GetUpperBound(0)
GridAddColumn("F" & i.ToString)
Next
End If
myRow = myTable.NewRow()
For i = MyArray.GetLowerBound(0) To MyArray.GetUpperBound(0)
myRow(i) = MyArray(i)
Next
myTable.Rows.Add(myRow)
strLine = sr.ReadLine
End While
sr.Close()
End Sub

------------ End Code ----------------
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
0 650

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1710
by: Clunixchit | last post by:
I would appreciate if you can criticise my code as well as if possible give advice on how to improve it. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h>...
5
12209
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
1
1179
by: Mircea Pleteriu | last post by:
Hi, I've created a test aspnet web application which contains one page only. There is only one label control placed on the page. The text of the label control is set on server side by the...
1
2017
by: VB Programmer | last post by:
I am getting a "IErrorInfo.GetDescription failed with E_FAIL" error when trying to do a "Fill" on a dataadapter. Any ideas?? The SQL command seems good (to an Access db). Here is the general...
4
1283
by: KB | last post by:
I realised that if I use datagrid and datasource is a datatable, when I created a new row and while on that row I exit the datagrid (ie. without moving into the next row) and focus onto another...
0
255
by: Terry Olsen | last post by:
I wrote the following code to load a DataTable with a CSV file. My problem is: If I include the line "MyTable.Clear()" before I start loading the Table, I'm presented with the 2nd line of my CSV...
1
9585
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
2593
by: Curtis | last post by:
Hello everyone: I have come to love the ease of updating PHP, since getting used to using it these past few years. Recently, however, when I upgraded from PHP 5.1 to PHP 5.2.0 and again when...
0
1188
by: gfergo | last post by:
We have a pretty straightforward page ('Page 1'). The codebehind creates a DataTable and binds the data to a Repeater which renders an HTML table on screen. The first column in the HTML table is...
5
13304
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
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,...
1
7021
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...
0
7478
tracyyun
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...
1
5035
isladogs
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...
0
4701
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...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
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 ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.