put first row of a datatable in an array list

sony

Newcomer
Joined
Oct 12, 2005
Messages
9
can some tell me how i can get the first row of a datatable and put it in an arraylist...

thanks in advance...
 
ah sorted it out... but have another problem

I managed to sort this problem out... this code is working fine for me .. i am getting the first row of my datatable..
now i have another problemm ahh i wish someone could help.. i have my arrlist yeah i need to get these values form the arraylist i was trying to put them in a string because then with that string i need to create a table for sql server....
dont know maybe someone else has another solution... for how i should do this.. but for shore i need the values of the array to be put in a CREATE TABLE and sent it to the database.


Visual Basic:
Dim arrlist As New ArrayList
        Dim row As DataRow
        row = oDT.NewRow()
        Dim o As Object

        Dim odrr As Object = oDT.Rows(0)

        For Each o In odrr.ItemArray
            odrr.Item(intcount) = o
            intcount = intcount + 1
            arrlist.Add(odrr)
        Next
 
sony said:
I managed to sort this problem out... this code is working fine for me .. i am getting the first row of my datatable..
now i have another problemm ahh i wish someone could help.. i have my arrlist yeah i need to get these values form the arraylist i was trying to put them in a string because then with that string i need to create a table for sql server....
dont know maybe someone else has another solution... for how i should do this.. but for shore i need the values of the array to be put in a CREATE TABLE and sent it to the database.


Visual Basic:
Dim arrlist As New ArrayList
        Dim row As DataRow
        row = oDT.NewRow()
        Dim o As Object

        Dim odrr As Object = oDT.Rows(0)

        For Each o In odrr.ItemArray
            odrr.Item(intcount) = o
            intcount = intcount + 1
            arrlist.Add(odrr)
        Next

Not quite sure about what you are trying to do, the code you provided doesn't make much sense. If you have filled your array with the names of the fields of your row, you can easily create all sorts of strings with that, just loop through the items of the arraylist, with a for each loop and append them to a stringbuilder object to the string that you desire. example in C#:
Visual Basic:
'Create the arraylist
ArrayList FieldList = new ArrayList();
StringBuilder strQuery = new StringBuilder();
'Add items to it
FieldList.Add("Item1");
FieldList.Add("Item2");
FieldList.Add("Item3");
foreach string strItem in FieldList
{
       strQuery.Append("This is the item: ");
       strQuery.Append(strItem);
}

MessageBox.Show(strQuery.ToString());
This will add item1..3 to the arraylist then append all these items to the stringbuilder object and show a messagebox showing the concatinated string.

In this manner you can create everything you want, from sentenses to queries to whatever.

Maybe this will help, but i would suggest to clarify you question so we can offer you a better explenation or solution.


Greetz
 
Back
Top