By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,722 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,722 IT Pros & Developers. It's quick & easy.

V2003: Multi-Table Dataset in DataGrid

P: n/a
Using the pubs database, for testing, and example, I'm trying to bind a
datagrid that draws data from multiple tables to use for updating multiple
rows at once. For my example, I want to display Titles, Authors & Prices,
and update the prices. The code I'm using is below, but I get an exception,
on binding the grid stating "A field or property with the name 'Pub_name'
was not found on the selected datasource". In the command window, in Debug
mode, I've verified that the data is in the dataset for both tables.
Pub_name is on the parent table, so how would I reference that on the
datagrid? Thanks in advance.


Dim daPub As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Publishers", conn)
Dim daTitles As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM
Titles", conn)

Dim ds As New DataSet
daPub.Fill(ds, "Publishers")
daTitles.Fill(ds, "Titles")

Dim data_relation As New _
DataRelation("TitlePublishers", _
ds.Tables("Publishers").Columns("Pub_Id"), _

DataGrid1.DataSource = ds
DataGrid1.DataKeyField = "Title_id"
DataGrid1.DataMember = "Titles"


The DataGrid's columns are as follows:
<asp:BoundColumn DataField="Title_ID" />
<asp:BoundColumn DataField="Title" HeaderText="Title" />
<asp:BoundColumn DataField="Pub_id" />
<asp:BoundColumn DataField="Pub_name" HeaderText="Publisher" />
<asp:TemplateColumn HeaderText="Price">
<asp:TextBox id="txtPrice" runat="server" MaxLength="6"
Columns="6" Text='<%# DataBinder.Eval(Container, "DataItem.Price") %>' />
Oct 30 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.