Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   V2003: Multi-Table Dataset in DataGrid (http://www.velocityreviews.com/forums/t381603-v2003-multi-table-dataset-in-datagrid.html)

bh 10-30-2006 07:52 PM

V2003: Multi-Table Dataset in DataGrid
 
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>




All times are GMT. The time now is 05:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.