V2003: Multi-Table Dataset in DataGrid

B

bh

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.

BH

conn.Open()
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"), _
ds.Tables("Titles").Columns("Pub_Id"))
ds.Relations.Add(data_relation)

DataGrid1.DataSource = ds
DataGrid1.DataKeyField = "Title_id"
DataGrid1.DataMember = "Titles"
DataGrid1.DataBind()

conn.Close()

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">
<ItemTemplate>
<asp:TextBox id="txtPrice" runat="server" MaxLength="6"
Columns="6" Text='<%# DataBinder.Eval(Container, "DataItem.Price") %>' />
</ItemTemplate>
</asp:TemplateColumn>
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top