-
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?
-
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. :)