|
-
Jun 24th, 2004, 05:01 PM
#9
Thread Starter
Member
Originally posted by CyberHawke
Here is a simple example that should provide a starting point for you.
VB Code:
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim dt As New DataTable("Customers")
dt.Columns.Add("firstname", System.Type.GetType("System.String"))
dt.Columns.Add("lastname", System.Type.GetType("System.String"))
dt.Columns.Add("department", System.Type.GetType("System.String"))
dt.Columns.Add("email", System.Type.GetType("System.String"))
dt.Columns.Add("phone", System.Type.GetType("System.String"))
Dim oReader As New IO.StreamReader("C:\Customers.txt")
Dim oCust As String
Dim oData() As String
Dim Index As Int32
Dim drItem As DataRow
Do
oCust = oReader.ReadLine
oData = oCust.Split(",".ToCharArray)
For Index = oData.GetLowerBound(0) To oData.GetUpperBound(0)
drItem = dt.NewRow
drItem(Index) = oData(Index).ToString
dt.Rows.Add(drItem)
drItem = Nothing
Next
Loop Until oCust Is Nothing
End Sub
Hi, I have been playing with this but am getting the following error...
---------------------
An unhandled exception of type 'System.NullReferenceException' occurred in textfiletest.exe
Additional information: Object reference not set to an instance of an object.
---------------------
The line highlighted is "oData = oCust.Split(",".ToCharArray)"
I expect its something simple but what am I doing wrong?
Last edited by grandad; Jun 24th, 2004 at 07:10 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|