ADO.Net Question

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I am trying to come up with a solution for a problem I am having. I have a
Business Object that creates a report at runtime based on an xml file. Then
for each textbox (field) I set the datafield. I want to be able to set the
datasource to equal to a dataset. This dataset structure would be retrieved
from the database (one table) and then I need to manually add the data to
the dataset. I am struggling on how is the best way to manually add the
data. The data is contained in custom classes. I was hoping to loop
through each column of the dataset (only one row) and add the data based on
column name. I then would use reflection to get the data using
myType.GetProperty((string)column name) into the dataset. For some reason I
am struggling on how to loop through the dataset to do this. The dataset
will only contain one datatable with one row of data. Any ideas?

Thanks
 
Hi Mike,

I am not sure that I fully understand.
However to loop through all columns in a datarow and retrieve row's value:
foreach (DataColumn col in table.Columns)

object o = table.Rows[0][col];

Does this help?
 
Thanks for the post. I am looking for a way to not retrieve but set the
value.

Thanks

Miha Markic said:
Hi Mike,

I am not sure that I fully understand.
However to loop through all columns in a datarow and retrieve row's value:
foreach (DataColumn col in table.Columns)

object o = table.Rows[0][col];

Does this help?


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mike" <mike> wrote in message news:[email protected]...
Hi,

I am trying to come up with a solution for a problem I am having. I
have
a
Business Object that creates a report at runtime based on an xml file. Then
for each textbox (field) I set the datafield. I want to be able to set the
datasource to equal to a dataset. This dataset structure would be retrieved
from the database (one table) and then I need to manually add the data to
the dataset. I am struggling on how is the best way to manually add the
data. The data is contained in custom classes. I was hoping to loop
through each column of the dataset (only one row) and add the data based on
column name. I then would use reflection to get the data using
myType.GetProperty((string)column name) into the dataset. For some
reason
I
am struggling on how to loop through the dataset to do this. The dataset
will only contain one datatable with one row of data. Any ideas?

Thanks
 
Hi Mike,

Do the inverse :)
table.Rows[0][col] = value;

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Mike said:
Thanks for the post. I am looking for a way to not retrieve but set the
value.

Thanks

Miha Markic said:
Hi Mike,

I am not sure that I fully understand.
However to loop through all columns in a datarow and retrieve row's value:
foreach (DataColumn col in table.Columns)

object o = table.Rows[0][col];

Does this help?


--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Mike" <mike> wrote in message news:[email protected]...
Hi,

I am trying to come up with a solution for a problem I am having. I
have
a
Business Object that creates a report at runtime based on an xml file. Then
for each textbox (field) I set the datafield. I want to be able to set the
datasource to equal to a dataset. This dataset structure would be retrieved
from the database (one table) and then I need to manually add the data to
the dataset. I am struggling on how is the best way to manually add the
data. The data is contained in custom classes. I was hoping to loop
through each column of the dataset (only one row) and add the data
based
on
column name. I then would use reflection to get the data using
myType.GetProperty((string)column name) into the dataset. For some
reason
I
am struggling on how to loop through the dataset to do this. The dataset
will only contain one datatable with one row of data. Any ideas?

Thanks
 
Back
Top