473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1307

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

Similar topics

6
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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
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
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...

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.