V2003: Multi-Table Dataset in DataGrid

Discussion in 'ASP .Net' started by bh, Oct 30, 2006.

  1. bh

    bh Guest

    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>
     
    bh, Oct 30, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nedu N
    Replies:
    1
    Views:
    1,839
    Chris Taylor
    Oct 31, 2003
  2. (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=

    Aldec Riviera v2003.06.1059 WinNT2kXP - new

    (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=, Oct 3, 2003, in forum: VHDL
    Replies:
    0
    Views:
    737
    (=?iso-8859-1?Q?=AF=60=B7=2E=2E=2E=F8=A4=B0=60=B0=
    Oct 3, 2003
  3. Nedu N
    Replies:
    2
    Views:
    2,209
  4. bh
    Replies:
    0
    Views:
    382
  5. Nedu N
    Replies:
    2
    Views:
    243
    Jacob Yang [MSFT]
    Oct 31, 2003
Loading...

Share This Page