why can I set grid's DataSource to a DataSet but not to a table in the DataSet?

B

Bennett Haselton

I have a DataGrid on a WebForm. When I select that DataGrid and go to
the "DataSource" property in the properties box, the drop-down lets me
select dataSet11, which is the name of an object instance of class
DataSet1, which VS.Net created for me derived from DataSet.

However, DataSet1 has a schema with two tables in it -- if I
right-click dataSet11 and pick "View Schema" it shows two tables,
wbuser and BennettEmployee.

Now, as soon as I set the DataSource property of my DataGrid to
dataSet11, the layout of the DataGrid on the WebForm changes to
display the columns "myusername", "mynickname", and "ID" -- these are
the columns in the wbuser table from the DataSet1 schema.

So, two questions:

- Does this mean that "wbuser" is somehow the "default" table in the
DataSet1 schema, so that if the DataSource is set to dataSet11, it
automatically maps to the "wbuser" table of that DataSet, as opposed
to the "BennettEmployee" table? Is there a way to change the default
table to "BennettEmployee"?

- More importantly, why does the DataSource dropdown in the IDE only
let me set the DataSource to a *DataSet*, instead of a table within
that DataSet? Since the data in the DataGrid is being pulled from a
table, why won't it let me specify a table?

Am I looking at this in some fundamentally wrong way?

-Bennett
 
M

Miha Markic [MVP C#]

Hi Bennet,

Bennett Haselton said:
I have a DataGrid on a WebForm. When I select that DataGrid and go to
the "DataSource" property in the properties box, the drop-down lets me
select dataSet11, which is the name of an object instance of class
DataSet1, which VS.Net created for me derived from DataSet.

However, DataSet1 has a schema with two tables in it -- if I
right-click dataSet11 and pick "View Schema" it shows two tables,
wbuser and BennettEmployee.

Now, as soon as I set the DataSource property of my DataGrid to
dataSet11, the layout of the DataGrid on the WebForm changes to
display the columns "myusername", "mynickname", and "ID" -- these are
the columns in the wbuser table from the DataSet1 schema.

So, two questions:

- Does this mean that "wbuser" is somehow the "default" table in the
DataSet1 schema, so that if the DataSource is set to dataSet11, it
automatically maps to the "wbuser" table of that DataSet, as opposed
to the "BennettEmployee" table? Is there a way to change the default
table to "BennettEmployee"?

The default table in this situation is the first table in collection or
first table created in dataset. You can change it by chagning the dataset
schema (put element containing your default table on the top of
- More importantly, why does the DataSource dropdown in the IDE only
let me set the DataSource to a *DataSet*, instead of a table within
that DataSet? Since the data in the DataGrid is being pulled from a
table, why won't it let me specify a table?

Use DataMember property for picking the table you want.
 

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