We help IT Professionals succeed at work.

How to connect to LINQ from ASP.NET

Last Modified: 2013-11-07
I have added an Linq .dbml to my ASP.NET project. I have added 1 stored procedure.
From a web page I have added
Imports System.Linq
Imports System.Data.Linq.

When I try to declare an instance of the DataContext, it does not show up in intellisense with and without using the Dim db as new  and Dim db.

 I have never worked with LINQ before and need some guidance on getting it up and running. Can someone show me the light?
Watch Question


I have read just about everything out there. I can not find any help on why I can not access my datacontext. I'm trying to find out if I missed any steps, or has anyone had this problem before?
Why you want to create instance of the datacontext.
You can do everything on the aspx page.
Have a look at the code I have pasted below
I havent added anything in the code behind to display data.
first create a dbml.
AdventureWorks is the name of the dbml file and
so the contexttypename for LinqDataSource will be AdventureWorksDataContext.

This is the link from where i have created application
<asp:GridView ID="gvProperties" GridLines="None" DataSourceID="LinqDataSource2" 
            runat="Server" CellPadding="4" ForeColor="#333333" Visible="false" >
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#E3EAEB" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#7C6F57" />
        <AlternatingRowStyle BackColor="White" />

      Where="ProductCategoryID = @SelectedCategory" 
      Select="new(ProductSubCategoryID, ProductCategoryID,Name, ModifiedDate, rowguid)" 
          Type="Int32" />

Open in new window


this was helpful, but I'm not there yet.

I am only able to declare the datacontext when I have tables in my .dbml. If I create my own class that who's properties reflect the recordset returning, the datacontext will not be available. Maybe if I tell you what I am trying to do it will be more helpful. I have a stored procedure that returns data from 3 tables (tblWorkSheet, tblRows, tblColumns). The goal is for the user to build a custom report by selecting from listbox controls any field/row from any worksheet. The listbox control data should contain rows/columns for the worksheet selected. I think it would be best to databind my controls to avoid having to requery the db each time the user select a different worksheet from the listbox.  I could create a datatable and load it with the query results and store it in a session variable so that I can requery each time the user selects a different worksheet, but my gut is telling me linq can help me.
Any advice?
This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.