Avatar of Jamara
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?
<ItemTemplate>
                                    <asp:Label ID="ddlInspType"  runat="server" Text='<%# DataBinder.Eval(((System.Data.DataRowView)Container.DataItem).Row.GetParentRow("tableName"),"fieldName") %>'></asp:Label>
                                </ItemTemplate>

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
Jamara

8/22/2022 - Mon
Bob Learned

See if this helps?

Get a Quick Start on Data Access with ADO.NET
http://www.asp101.com/articles/jay/adodotnet/default.asp

Jamara

ASKER
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.
Jamara

ASKER
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.
Jamara

ASKER
TheLearnedOne,  
   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)
    xState=theBox.checked;    
 
        elm=theBox.form.elements;
        for(i=0;i<elm.length;i++)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
            {
            //elm[i].click();
            if(elm[i].checked!=xState)
            elm[i].click();
            //elm[i].checked=xState;
            }
    }
 
    //-------------------------------------------------------------
    //----Select highlight rows when the checkboxes are selected
    //
    //-------------------------------------------------------------
    function HighlightRow(chkB)    {
    var oItem = chkB.children;
    xState=oItem.item(0).checked;    
    if(xState)
        {chkB.parentElement.parentElement.style.backgroundColor='lightblue';
           // grdEmployees.SelectedItemStyle.BackColor
         chkB.parentElement.parentElement.style.color='white'; 
           // grdEmployees.SelectedItemStyle.ForeColor
        }else 
        {chkB.parentElement.parentElement.style.backgroundColor='white'; 
             //grdEmployees.ItemStyle.BackColor
         chkB.parentElement.parentElement.style.color='black'; 
             //grdEmployees.ItemStyle.ForeColor
        }
    }
    
    </script>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
       
    
    <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>
        
    </div>
    <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:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ErrorMessage="Delivery Number is a required field." ControlToValidate="txtbxDelNum" >
      </asp:RequiredFieldValidator>
 
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
        <asp:LinkButton ID="CreateFile" runat="server">Create label file</asp:LinkButton>
 
    </p>
    
   <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" /> 
    <Columns> 
           <asp:TemplateField HeaderText="Select"> 
           <ItemTemplate> 
           <asp:CheckBox ID="chkSelect" onclick="javascript:HighlightRow(this);"
            runat="server" OnCheckedChanged= "grdEmployees_CheckedChanged" 
            Checked="True" />
           </ItemTemplate> 
           </asp:TemplateField>            
        
           <asp:BoundField runat="server" HeaderText="Line Number"  SortExpression="lineNumber" 
            Text="<%# DataBinder.Eval(Container.DataItem, "LINE_NUMBER") %>" 
            DataField="Line_Number"> 
           </asp:BoundField >    
         
           <asp:BoundField  runat="server" HeaderText="End Unit UID Number"  SortExpression="UIDNumber" 
            Text="<%# DataBinder.Eval(Container.DataItem, "UID_No") %>" 
            DataField="UID_NO">
            </asp:BoundField>   
 
 
 
 
    </Columns>         
           <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" />   
 
     </asp:GridView>
 
 
     </form>
</body>
</html>
 
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
 
        Try
 
            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")
 
            DataGV.DataBind()
 
 
 
 
        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

ASKER CERTIFIED SOLUTION
Bob Learned

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
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
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jamara

ASKER
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!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.