Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

tinac99 (Programmer) (OP)
16 Sep 11 17:19
Hi,

I have need to perform a sql on the following tables:
Order
------
order_id
order_date
cust_id

Order_Items
---------------
Order_id
item_id

so I have the following linqtosql:
            var query = from o in dc.order
                        select new
                        {
                            OrderId = o.order_id,
                            OrderDate = o.order_date,
                            CustId = o.cust_id,
                            items = (from oi in dc.Order_Items
                                   where oi.order_id == o.orderId  
                                   select new { oi.item_id}),

                        }

        Gridview1.DataSource = query;
        Gridview1.DataBind();

I plan to have this query in gridview, suppressing repeating columns[orderid, orderdate, custid] if there are multiple items for that order.  Can anyone tell me how to code the mark-up tags so that the Gridview1 items column can display the items collection?  This is what I have so far:

    <asp:GridView ID="GridView1" runat="server" UseAccessibleHeader="True"
        DataKeyNames="OrderId"  SelectedIndex="1"
        AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" PageSize="50">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="OrderId"
            DataNavigateUrlFormatString="OrderAdd.aspx?update=true&orderid={0}"
            DataTextField="OrderId" NavigateUrl="OrderAdd.aspx" HeaderText="OrderId" SortExpression="OrderId"  />

          <asp:boundfield datafield="OrderDate" readonly="true"  headertext="OrderDate"/>

            <asp:TemplateField HeaderText="items" SortExpression="items">
                <ItemTemplate>
                    <asp:ListBox ID="ListBox1" runat="server" DataTextField="items" DataValueField="items" DataSource="items"></asp:ListBox>
                </ItemTemplate>
            </asp:TemplateField>        
    </Columns>
    </asp:GridView>

Thanks for your input!

Best,

TinaC
 
jmeckley (Programmer)
19 Sep 11 12:36
I think

CODE

<asp:ListBox ID="ListBox1" runat="server" DataSource="items"/>
should do it since items is just a collection of strings. however there are 2 subtle problems with you query.
1. there is a select n+1 issue
2. there is no limit to the amount of data returned.

neither of these issues will be apparent when developing or with small amounts of data, but if you get into 1000s of orders the system will grind to a halt and then crash.

select n+1 exists because you have the initial query for orders and then another query for each set of order items. so if you have 10 orders it will execute 11 queries. 100 orders 101 queries, etc. remote IO calls, like querying the database, are the more expensive operations you can perform so you want to guard against excessive database queries.

without a limit of the number of orders you may return 100s or 1000s of records. this query doesn't appear to have any criteria/predicates either so the entire table of orders and order items will be returned. the linqtosql provider has an implementation for Skip(n) and Take(n) which allow you to query a page of records. using Skip/Take in conjunctions with a total count of all orders

CODE

select count(1) from [order table]
will allow you to construct the paging links and get much better performance. you can use the asp.net 3.5 ListView and DataPager to assist with this type of functionality.

Jason Meckley
Programmer

FAQ855-7190: Database Connection Management
FAQ732-7259: Keeping the UI responsive

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close