3
Answers

my StreamReader and Split Method doesn't worked. O.o

my WindowsApplication program has the following labels in my form named 'frmCustomerDetails'.

  • lblCustomerID - displays the Customer ID (int value)
  • lblCompanyName - string value
  • lblAddress - string value
  • lblContactPerson - string value
  • lblContactNo - string value (or is it an int value)

In a windows application program, I should able to display my records coming from a .txt file. Using the StreamReader, I should able to display my records to the given labels.

I have a mp.txt file found in C:

               here's a sample input inside the mp.txt

                  12345#John#Ohio#Jake#Arizona#

                           wherein '#' is the delimeter 

I should able to display my records separately using the Split method.

However, my codes doesn't run correctly:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

        private void frmCustomerDetails_Load(object sender, EventArgs e)
        {
            StreamReader reader = new StreamReader(@"C:\mp2.txt");
            string line;
            string[] records;

            while (!reader.EndOfStream)
            {
                line = reader.ReadLine();
                records = line.Split("#");

                records[0] = long.Parse(txtCustomerID.Text);
                records[1] = txtContactPerson.Text;
                records[2] = txtAddress.Text;
                records[3] = txtContactPerson;
                records[4] = txtContactNo;
            }

            reader.Close();

Any way to fix these codes?

Answers (3)
Next Recommended Forum