i got a data like tis 1(0-AGF-MYR-100101), i wan split to 4 part(0 , AGF, MYR ,100101)
and after tis i nid to add 4 new columns to a datatable to display the value!
how nid i do???

Dim writer As StreamWriter = File.CreateText("D:\ IMS.csv")

        For i As Integer = 1 To ds.Tables(0).Columns.Count - 1
            writer.Write(ds.Tables(0).Columns(i))
            If i < ds.Tables(0).Columns.Count - 1 Then
                writer.Write(",")
            End If
        Next
        writer.Write(writer.NewLine)
        For Each dr As DataRow In ds.Tables(0).Rows
            For i As Integer = 0 To ds.Tables(0).Columns.Count - 1

                If Not Convert.IsDBNull(dr(i)) Then
                    writer.Write(dr(i).ToString())
                End If
                If i < ds.Tables(0).Columns.Count - 1 Then
                    writer.Write(",")

                End If
            Next
            writer.Write(writer.NewLine)
        Next

THanks!!!!!!!!!!

Easy Stuff,,

textbox1 has whatever text you want to parse,, hence 0-AGF-MYR-100101

and puts it in the listbox1 one below the other like this

0
AGF
MYR
100101

Dim values As String

        values = TextBox1.Text

        Dim sites As String() = Nothing

        sites = values.Split("-")

        Dim s As String

        For Each s In sites
            ListBox1.Items.Add(s)

        Next s

Edited 6 Years Ago by marketingmaniac: n/a

Dim myDataString As String = "0-AGF-MYR-100101"
        Dim myArray() As String = myDataString.Split("-") '// separate each item.
        For i As Integer = 0 To myArray.Length - 1 '// loop thru myArray.
            '// code to add datatable column here.
            MsgBox(myArray(i)) '// display result.
            '//
        Next

may i know how to add 4 new column to existing table("customer") automatic after split the string?
how to insert the listbox data into the new column that create?
thanx....

this is how i add colums to a listbox

ListView3.Columns.Add("NAME", 150, HorizontalAlignment.Left)
        ListView3.Columns.Add("SCREEN NAME", 150, HorizontalAlignment.Left)
        ListView3.Columns.Add("LOCATION", 150, HorizontalAlignment.Left)

and to populate it i do this

For Each node In doc.DocumentElement.SelectNodes("//user")
                Dim str(7) As String
                Dim itm As ListViewItem

                str(0) = node.Item("name").InnerText
                str(1) = node.Item("screen_name").InnerText
                str(2) = node.Item("location").InnerText
                str(3) = node.Item("url").InnerText
                str(4) = node.Item("followers_count").InnerText
                str(5) = node.Item("friends_count").InnerText
                str(6) = node.Item("statuses_count").InnerText
               
                itm = New ListViewItem(str)
              
            
                                            ListView3.Items.Add(itm)
                                            ListBox6.Items.Add(str(1))
                                      
                          
                End If

Edited 6 Years Ago by marketingmaniac: n/a

Soory,i don't really understand how the code above function!
wat u means izzit add 4 column to listbox for store the data that splitted?

how put the data that store at listbox to datatable("customer") and display?
thanks....

ListBox1.Items.Add("CUSTOMER")
        ListBox1.Items.Add("--------")

        Dim values As String

        values = "0-AGF-MYR-100101"

        Dim sites As String() = Nothing

        sites = values.Split("-")

        Dim s As String

        For Each s In sites
            ListBox1.Items.Add(s)

        Next s

ListBox1.Items.Add("--------")

wat means for tis?Add("------")

thanks?

why nid add table "customer" to listbox (ListBox1.Items.Add("CUSTOMER"))?
i wan add the listbox data to table.Before add the listbox data,i wan create 4 new column at this existing table for store the listbox data.
any1 can teach me hw 2 do?
thanks...

may i know how to add 4 new column to existing table("customer") automatic after split the string?

Assuming that the text top split is in a string called TextTosplit, and the split charcter is the "-", you can separate then into a string array using some thing like

Dim StringParts as String() = TextToSplit.Split("-"c)

To add this info in the ds.tables(0) as a new row you can:

If stringParts.Lenght = 4 Then' To verify that has the required number of fileds
    ds.tables(0).Rows.Add(StringParts)
End If

Hope this helps

thats just so you can seperate the collum so you can see the header but
its better to place it in a list-view instead of listbox if you need you can
try it on your side in a list-view and use the other code i gave ya to populate
the listview box instead of a listbox so you have the header Customer
if you use the listview instead, you can just add this to have the header

ListView1.Columns.Add("CUSTOMER", 150, HorizontalAlignment.Left)

@marketingmaniac:
On the original post jcfans wrote

may i know how to add 4 new column to existing table("customer") automatic after split the string?

Why is needed a Listview to add data to the existing "customer" table?

Wich is the mechanism that adds the items from the listview to the database?

Is necessary the header in order to add the records to the table?

Sorry, as jcfans I am lost.

bcoz i nid add the data that splitted to a table and display the all data of the data

well then,, what kind of data base are you trying to add the customer too,,

first,,
I showed you how to place the data into clean sections.

Second.
I showed you how to place that code into a ListBox and A Listview.

Third.
You should mark this post as SOLVED.

Forth.
You should open a new post and ask the following.

How to place data into a database. (( and then i will help you solve that one ))

Mike

Edited 6 Years Ago by marketingmaniac: n/a

This question has already been answered. Start a new discussion instead.