Accessing stored procedures using LINQ in vb.net

Accessing stored procedures using LINQ

Open ServerExplorer

Open NorthWindDataConnection

Drag & drop CustOrderList (Stored Procedure) on Form (which contains tables we drag & dropped (cust, order, - - - -))

(The stored procedure we already have)

Rclick anywhere on design and click ShowMethodSpan. Now a window will be opened showing all stored procedure

Save

Note: The above steps will add the definition of the stored procedure with LINQ to sql classes.

 

The stored procedure used in LINQ:

ALTER PROCEDURE CustOrderList

@ Customer ID nchar (5)

AS

SELECT Product Name, Total = SUM   - - >  (quantity)

FROM ProductsP, [Order details] Od, Orders O, Customers c

WHERE C.CustomerID = @ Customer ID

AND C.CustomerID = O.CustomerID

AND O.OrderID = OD.OrderID AND

OD.ProductID = D.ProductID

GROUP BY Product Name

Click on GridView2 task and edit columns

Expand Command Field à Select à Add

Button type: button

SelectText: ShowOrders

Double click on GridView2

“GridView2_SelectedIndexChanged

String cid;

TableCell tcCID = (TableCell) GridVIew2. SelectedRow. Cells [3];

cid = tcCID.Text;

Response.Redirect (“ShowOrdersHistoryByCID.aspx? cid = “ + cid);

Website [menu] - - >Add NewItem – Name: ShowOrdersHistoryByCID

Place a GridView Control

 

// Page_Load

String CustomerId = request.QueryString [“cid”];

NorthWindDBDataContext dc = new NorthWindDBDataContext ();

Var ordersHistory = dc.CustOrderHist (CustomerId);

GridView1.DataSource = orderHistory;

GridView1.DataBind ();