Results 1 to 10 of 10

Thread: storing multiple userdetails from a textfile

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Posts
    42
    Originally posted by CyberHawke
    Here is a simple example that should provide a starting point for you.

    VB Code:
    1. Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
    2.     Dim dt As New DataTable("Customers")
    3.     dt.Columns.Add("firstname", System.Type.GetType("System.String"))
    4.     dt.Columns.Add("lastname", System.Type.GetType("System.String"))
    5.     dt.Columns.Add("department", System.Type.GetType("System.String"))
    6.     dt.Columns.Add("email", System.Type.GetType("System.String"))
    7.     dt.Columns.Add("phone", System.Type.GetType("System.String"))
    8.     Dim oReader As New IO.StreamReader("C:\Customers.txt")
    9.     Dim oCust As String
    10.     Dim oData() As String
    11.     Dim Index As Int32
    12.     Dim drItem As DataRow
    13.     Do
    14.         oCust = oReader.ReadLine
    15.         oData = oCust.Split(",".ToCharArray)
    16.         For Index = oData.GetLowerBound(0) To oData.GetUpperBound(0)
    17.             drItem = dt.NewRow
    18.             drItem(Index) = oData(Index).ToString
    19.             dt.Rows.Add(drItem)
    20.             drItem = Nothing
    21.         Next
    22.     Loop Until oCust Is Nothing
    23. 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
  •  



Click Here to Expand Forum to Full Width