DataColumn Parsing

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

Hi All,

Not sure if parsing is the correct word but here is what I'm trying to
do:

I have a method that returns a dataset that uses a select statement
that comprises three union all'd select statements (i.e. "select
author from table1 union all select author from table 2...").

The end result is a small dataset with one column and four rows
including the column header (three rows of data). What I'm trying to
do is iterate through the column asiging each row (there's only one
field per row) to a three different text boxes. I've done this a
hundred times with one row and many columns using code similar to
this:

foreach (DataRow dr in dt.Rows)
{
txt1.Text = dr[0].ToString();
txt2.Text = dr[1].ToString();
txt3.Text = dr[2].ToString();
}

But can't figure out how to iterate vertically through a column using
a similar method. How do I di that?

Thanks for any help.
 
What do you mean by iterating vertically through a column? Can you give an
example as to what you are trying to achive?

Adrian.
 
Adrian,

The dataset that I'm returning has only one column (col1) and four
rows(row1 - row4). I would like the data from col1,row1 in textbox1,
the data from col1,row2 in textbox2, data from col1,row3 in
textbox3...etc.

Thanks
 
Adrian,

The dataset that I'm returning has only one column (col1) and four
rows(row1 - row4). I would like the data from col1,row1 in textbox1,
the data from col1,row2 in textbox2, data from col1,row3 in
textbox3...etc.

Thanks

What I did was created an ArrayList and added all of my textboxes to
it. Then using a simple FOR loop, I iterated through the DataTable
placing the values into the textboxes:

ArrayList aList = new ArrayList();
aList.Add(textBox1);
aList.Add(textBox2);
aList.Add(textBox3);

for (int i = 0; i < dt.Rows.Count-1; i++)
{
((TextBox)aList).Text = ((DataRow)dt.Rows)[0].ToString();
}

A bit ugly and I know it can be cleaned up. I'm interested to know if
you come up with anything as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top