Loading data from a Dataset that is created at Runtime

G

Guest

Hi,
I understand in order to extract data from the tables in a Dataset and
setting it to control, the following csharp syntax applies.

textBox1.Text = northwindDataSet.Customers[3].ContactName;

However I am creating a Dataset at runtime when query results from a
WebService are returned as a Dataset. I know that it will contain only one
table (Table1) and contain and number of fields (Field1, Field2, Field3).
And Visual Studio will not allow me to compile the below code as these
references do not exist at Runtime.

textBox1.Text = myDataSet.Table1[0].Field1;

How else may I reference Dataset tablenames/fieldnames that do not exist at
compile time?

Any help would be greatly appreciated.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Khurram said:
Hi,
I understand in order to extract data from the tables in a Dataset and
setting it to control, the following csharp syntax applies.

textBox1.Text = northwindDataSet.Customers[3].ContactName;

So you have a strong typed dataset.

However I am creating a Dataset at runtime when query results from a
WebService are returned as a Dataset.

It's returned as a strong typed dataset ???
I know that it will contain only one
table (Table1) and contain and number of fields (Field1, Field2, Field3).
And Visual Studio will not allow me to compile the below code as these
references do not exist at Runtime.

textBox1.Text = myDataSet.Table1[0].Field1;

It should be dataset.Tables[0].Rows[0]["Field1"];

Again, it does depend if the dataset is strong typed or not
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi

I just saw your other post and effectively you are not using a strong typed
dataset, just use the code I posted.
 
G

Guest

Hi,
So you have a strong typed dataset.

Firstly as you know I have not got a strongly typed dataset but I think I
should. How would I do that and should i do it at the client or web service
side? I think it would be good if it is returned as a strongly typed
dataset.
It should be dataset.Tables[0].Rows[0]["Field1"];

Since my aim for this dataset is to populate the fields of my client website
with the contents of the dataset, I wrote the following code. There is data
in the Dataset

testDatasetTextBox.Text = assessmentDataSet.Tables[0].Rows[0]["aap_key"];

This gives me an error underlining the Dataset (assessmentDataSet):

Cannot implicitly convert type 'object' to 'string'. An explicit conversion
exists (are you missing a cast?)

How else do I extract data and assign it to a control?

Thank you again

Khurram
 
G

Guest

Hi,

Sorry I was not thinking straight. Just need to convert the field being
picked up to string using ToString(). For example

testDatasetTextBox.Text =
assessmentDataSet.Tables[0].Rows[0]["aap_key"].ToString();


Works fine Thanx.

Khurram



Khurram said:
Hi,
So you have a strong typed dataset.

Firstly as you know I have not got a strongly typed dataset but I think I
should. How would I do that and should i do it at the client or web service
side? I think it would be good if it is returned as a strongly typed
dataset.
It should be dataset.Tables[0].Rows[0]["Field1"];

Since my aim for this dataset is to populate the fields of my client website
with the contents of the dataset, I wrote the following code. There is data
in the Dataset

testDatasetTextBox.Text = assessmentDataSet.Tables[0].Rows[0]["aap_key"];

This gives me an error underlining the Dataset (assessmentDataSet):

Cannot implicitly convert type 'object' to 'string'. An explicit conversion
exists (are you missing a cast?)

How else do I extract data and assign it to a control?

Thank you again

Khurram
 

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

Top