Results 1 to 2 of 2

Thread: to get the value

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    to get the value

    im trying to get the value of each record returned in a datalist.

    I can get the column headings but i want to go through each record and get back each column value. how do i do this?

    this is what i have:

    Code:
    for(int j = 0; j < dt.Rows.Count; j++)
                {
                    for(int i = 0; i < dt.Columns.Count; i++)
                    {
                        MessageBox.Show(dt.Columns[i].ToString()); 
                    }
    
                    MessageBox.Show(dt.Rows[j].ToString());                
                }
    but it obviously doesnt seem to work. the last messagebox shows "system.data.datarow". any ideas anyone?

    any ideas?

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this?
    Code:
            SqlConnection cn=new SqlConnection("user id=sa;password=password;initial catalog=northwind");
            SqlDataAdapter da=new SqlDataAdapter();
            DataTable dt=new DataTable();
            private void Form1_Load(object sender, System.EventArgs e)
            {
                da.SelectCommand=new SqlCommand("select * from territories",cn);
                da.Fill(dt);
    
                string s="";
                for(int i=0;i<dt.Rows.Count;i++)
                {
                    for(int j=0;j<dt.Columns.Count;j++)
                    {
                        s+=dt.Rows[i][j].ToString()+"\t";
                    }
                    s+="\n";
                }
                MessageBox.Show(s);
            }
    if not, sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width