Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
com = new SqlCommand("select Message_State from Table_3 where Message_State='CR'", con);
            
Int32[] sam = new int[10];

                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = com;
                    con.Open();
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        
                        sam[i] = Convert.ToInt32(ds.Tables[0].Rows[i][0]);
                        TextBox2.Text = sam[i].ToString();
                        TextBox2.Text = Convert.ToString(ds.Tables[0].Rows.Count);
                            
                    }

            con.Close();
}



im able to get the count of the selected column but how do i put each cell value into an array... please help.....
Posted
Updated 4-Apr-12 7:21am
v2
Comments
El_Codero 4-Apr-12 13:22pm    
[EDIT: Code Tags added]

Hi,
I presume you want to put every record in an array of int. If so, this is the code:

C#
Int32 [][] sam = new Int32[ds.Tables[0].Rows.Count][ds.Tables[0].Columns.Count]
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  for (int j=0;j<ds.tables[0].columns.count;j++)>
    sam[i][j] = Convert.ToInt32(ds.Tables[0].Rows[i][j]);


You need to define a 2-dimentional array as you have a list of records.

I hope it will help,
Cheers.
 
Share this answer
 
In order to get an array of arrays holding cell values you need something like this:

XML
...
da.Fill(ds);

List<object> list = new List<object>();

foreach(DataRow row in  ds.Tables[0].Rows)
{
    List<object> cells = new List<object>();

    foreach (DataColumn col in ds.Tables[0].Columns)
    {
        cells.Add(row[col]);
    }
    list.Add(cells.ToArray());
}

return list.ToArray();


The returned value vill have this type object[][]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900