Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp.net 4 read csv file into Gridview

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Getting Error on converting an array into a string
Code:
       Dim Filename As String = Session("SPMIDTextFile")
        Dim SPMIData, LineToRead As String
        Dim SPMID, CostTracker As String
        SPMIData = GetFileContents(Filename)
        Dim strReader As New StringReader(SPMIData)
        Dim a As Integer

        Dim SPMIDCostrakr As ArrayList
        Do While strReader.Peek() >= 0
            SPMIDCostrakr = strReader.ReadLine() '<<< Blue squiggly here, see below
        Loop
        ' Bind the results to the GridView   
        GridView1.DataSource = SPMIDCostrakr
        GridView1.DataBind()

Value of type 'string' cannot be converted to 'system.collections.arraylist'

What do I need to do to read a .CSV file into a datagrid?
BTW: its some 8000 lines long

DougP
 

Have to add to arrarys

Code:
SPMIDCostrakr.Add(strReader.ReadLine())


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Ok that works, My file has two columns separated by a comma, and I would liek to bring it into the Gridview in 2 columns. How can I dod that?
SPMID | Costrakr
9999, ADSSDS
8888, DJJDJJ
etc
now it brings it into one column like so
the heading has the comma in it, and there is only one column
SPMID,CostTracker
10082A1,AABD0006
I need to use the split command looking for a comma and then make a 2 column array?

Code:
        Dim Filename As String = Session("SPMIDTextFile")
        Dim SPMIData As String
        SPMIData = GetFileContents(Filename)
        Dim strReader As New StringReader(SPMIData)
        Dim SPMIDCostrakr New ArrayList
        Do While strReader.Peek() >= 0
            SPMIDCostrakr.Add(strReader.ReadLine())
        Loop
        ' Bind the results to the GridView   
        GridView1.DataSource = SPMIDCostrakr
        GridView1.DataBind()

DougP
 
Use the Split() method on the "," when add it to the the ArrayList
 
ok can someone give me an example?
Split ???

DougP
 
Have you heard of Google?
Do some research before you ask for help

Try:
Code:
SPMIDCostrakr.Add(strReader.ReadLine().Split(","))

Something like that. You will to play around with it and see what works for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top