LINQ With Stored Procedures

How to Use LINQ to SQL?

  • Step 1: Make a new “Data Connection” with database server. View -> Server Explorer -> Data Connections -> Add Connection
  • Step 2: Add LINQ To SQL class file.
  • Step 3: Select tables and Stored Procedures from database and drag and drop into the new LINQ to SQL class file.
  • Step 4: Added tables to class file.

CRUD Operation using LINQ to SQL?

Design
CRUD OPERATION
Curd_Operation.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Curd_Operation : System.Web.UI.Page
{
    DataClassesDataContext dc = null;

    public Curd_Operation()
    {
        dc = new DataClassesDataContext();
    }

     private void ShowEmp()
    {
        var data = dc.tblEmployees.ToList();
        GridView1.DataSource = data;
        GridView1.DataBind();
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        ShowEmp();
    }

     protected void btnInsert_Click(object sender, EventArgs e)
    {
        dc.usp_InsertEmp(txtEmpName.Text, Convert.ToDecimal(txtEmpSalary.Text), txtEmpDoj.Text);
        Show();
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        dc.usp_UpdateEmp(txtEmpName.Text, Convert.ToDecimal(txtEmpSalary.Text), txtEmpDoj.Text, Convert.ToInt32(txtEmpId.Text));
        Show();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        dc.Usp_DeleteEmp(Convert.ToInt32(txtEmpId.Text));
        Show();
    }
}

No comments:

Post a Comment

Xamarin Android Project App

Xamarin Android Project App 1. Xamarin -- Make a CALCULATOR Android App   https://drive.google.com/open?id=0B8OPCXLrtKPmWC1FWWtFM2lraVk...