Avatar of Jamara
Flag for United States of America asked on

Create and fill DataSet in App_Code DataSet.xsd and/or DataSet.xss items

during a peer review, my co-worker told me to eliminate my code and replace it with code of this type.  Where can I find a good resource for creating a dataset in App_Code, creating teh query, filling the dataset, then filling the grid view using something like this?
                                    <asp:Label ID="ddlInspType"  runat="server" Text='<%# DataBinder.Eval(((System.Data.DataRowView)Container.DataItem).Row.GetParentRow("tableName"),"fieldName") %>'></asp:Label>

I've read so much and cannot find instructions for creating and filing a dataset in the app_code section of my website.
I need to read three Oracle tables and fill a datagrid with values from each.  There is one parent and two children for a relationship.  How do I fill the datagrid using code as above?
Visual Basic ClassicASP.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon
Bob Learned

See if this helps?

Get a Quick Start on Data Access with ADO.NET


I have found that this can be accomplished by 'Adding a New item and then choosing 'Data Set'.  Once the .xsd and .xss items are opened in designer mode, you can select 'Date Set' from the toolbox and a wizard appears.  Here you can identify your connection, your database tables, choose columns, create a quiery, create a data adapter, create a data relationship.   I'm still new to this and still looking around for info.  Anyone have any good source of info for this?  I'm still trying to figure out how to get the wizard to appear so that I can do same for the second and third tables.

Got by the step where i'm adding tables. Now to connect the data grid to these tables...anyone???  
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Bob Learned

You should be able to set the DataSource for the GridView, and then call the DataBind method.

   Thanks for responding!   I appreciate the suggestion.
   Hopefully, we can take this one step further.  I am working on using 3 tables to fill one dataset.  From those 3 tables, 2 tables contain data I want to display on one datagrid.  I am using ASP.NET 3.5 and ADO.NET's Dataset Designer.  I've done all of the designer steps but don't know how to fill one datagrid with data from 2 different tables.  I also want to order the grid based on the value of one datafield in the first (of the two) tables.  
   Here is the scenerio:  Read the first table using the input DelNum data field.  I should extract one record.  Read the second table using the shipment_id from the first table's record.  I can extract one to many records.  Read the thrid table using the shipment_id from the first table's record.  I can extract one to many records.  Create one datagrid ordered by the line_number of the second tables record(s).
  I'm getting an error message stating:  ('<asp:BoundField runat="server" HeaderText="Line Number"  SortExpression="lineNumber"               Text="') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.            

In aspx page:
<%@ Page Language="VB" AutoEventWireup = "false" CodeFile="~/MainPage.aspx.vb" Inherits="Mainpage"  %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Label Page</title>
<script type="text/javascript">
    // Select all the checkboxes (Hotmail style)
    function SelectAllCheckboxes(spanChk){
    // Added as ASPX uses SPAN for checkbox 
    var oItem = spanChk.children;
    var theBox=oItem.item(0)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
    //----Select highlight rows when the checkboxes are selected
    function HighlightRow(chkB)    {
    var oItem = chkB.children;
           // grdEmployees.SelectedItemStyle.BackColor
           // grdEmployees.SelectedItemStyle.ForeColor
    <form id="form1" runat="server">
    <br />
    <asp:RadioButton ID="rbIIEbl" runat="server" Checked="True" />
    <asp:Label ID="lblIIELbl" runat="server" 
            Text="Interior / Intermediate and External Labels"></asp:Label>
    <br />
    <asp:RadioButton ID="rbMSLbl" runat="server" Checked="True" />
    <asp:Label ID="lblMSLbl" runat="server" Text="Material Shipping Label"></asp:Label>
    <p style="margin-left: 60px">
    <asp:Label ID="DelNumLabel" runat="server" Text="Delivery Number"></asp:Label>
    <asp:TextBox ID="txtbxDelNum" runat="server" ToolTip="Enter Delivery Order Number">
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ErrorMessage="Delivery Number is a required field." ControlToValidate="txtbxDelNum" >
        <asp:LinkButton ID="CreateFile" runat="server">Create label file</asp:LinkButton>
   <asp:CheckBox id="chkAll" 
      onclick="javascript:SelectAllCheckboxes(this);" runat="server" 
      AutoPostBack="false" ToolTip="Select/Deselect All"  />
    <asp:GridView ID="DataGV" runat="server"  AutoGenerateColumns="False" cellpadding="4" 
     GridLines="Horizontal" BackColor="White" BorderColor="#336666" BorderStyle="Double" 
     BorderWidth="3px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"  Height="1px" 
     Width="100%" AllowSorting="True" HorizontalAlign="Center" AllowPaging="True"> 
    <RowStyle BackColor="White" ForeColor="#333333" /> 
           <asp:TemplateField HeaderText="Select"> 
           <asp:CheckBox ID="chkSelect" onclick="javascript:HighlightRow(this);"
            runat="server" OnCheckedChanged= "grdEmployees_CheckedChanged" 
            Checked="True" />
           <asp:BoundField runat="server" HeaderText="Line Number"  SortExpression="lineNumber" 
            Text="<%# DataBinder.Eval(Container.DataItem, "LINE_NUMBER") %>" 
           </asp:BoundField >    
           <asp:BoundField  runat="server" HeaderText="End Unit UID Number"  SortExpression="UIDNumber" 
            Text="<%# DataBinder.Eval(Container.DataItem, "UID_No") %>" 
           <AlternatingRowStyle BackColor="Silver" /> 
           <FooterStyle BackColor="#009900" Font-Bold="True" ForeColor="White" Font-Size="Small" HorizontalAlign="Right" />   
           <PagerSettings PageButtonCount="30" Mode="NumericFirstLast" NextPageText="" PreviousPageText="" Position="TopAndBottom" /> 
           <PagerStyle BackColor="Silver" ForeColor="White" HorizontalAlign="Center" Font-Names="Verdana" Font-Size="Small" />   
In aspx.vb page:
Protected Sub GetShipInfo(ByVal DelNum As String)
        Dim myDataSet As New ShipHdrShipLinesUID
        Dim ShipHdrDA As New ShipHdrShipLinesUIDTableAdapters.ShipHdrTableAdapter
        Dim ShipLinesDA As New ShipHdrShipLinesUIDTableAdapters.ShipLinesTableAdapter
        Dim UIDDA As New ShipHdrShipLinesUIDTableAdapters.UIDTableAdapter
            ShipHdrDA.Fill(myDataSet.ShipHdr, DelNum)
            ShipLinesDA.Fill(myDataSet.ShipLines, shipment_id)
            UIDDA.Fill(myDataSet.UID, shipment_id)
            DataGV.DataSource = myDataSet.Tables("ShipLines")
            DataGV.DataSource = myDataSet.Tables("UID")
        Catch ex As Exception
            Dim Util = New Utilities()
                    Util.LogError(System.Reflection.MethodBase.GetCurrentMethod(), "Error obtaining shipping and line item data records.", ex)
                 Throw New Exception(" ")
       End Try
    End Sub

Open in new window

Bob Learned

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

Thanks!  I don't use that type statement much so the explanation along with the code was helpful.

I have more errors but want to accept this solution as an answer to the question I asked.  

I'll submit the next set of questions based on the new error messages shortly.  Thanks again!
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.