3-tier with Linq & StoreProcedure

Default.aspx

<form id="form1" runat="server">
    <div>
    <center>
    <table>
    <tr>
    <td>name</td>
    <td>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>mobile</td>
    <td>



        <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td colspan="2">
        <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
    </td>
    </tr>
    </table>
        <br />
        <asp:GridView ID="GridView1" runat="server" BackColor="White"
            BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4"
            ForeColor="Black" GridLines="Horizontal" Width="280px">
            <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        </asp:GridView>
    </center>
    </div>
    </form>



Default.aspx.CS

public partial class _Default : System.Web.UI.Page
{
    bal b = new bal();
    SqlConnection con = new SqlConnection(@"Data Source=SQLDB;Persist Security Info=True;User ID=Demoh;Password=Demo1@");
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            _show();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if(b.save(txtName.Text,txtMobile.Text)>0)
        {
            Response.Write("Data Inserted Successfully");
            txtName.Text = "";
            txtMobile.Text = "";
        }
        Response.Write("<i><h4>Data Inserted Successfully");
        txtName.Text = "";
        txtMobile.Text = "";
        _show();
    }
    public void _show()
    {
        SqlDataAdapter da = new SqlDataAdapter("select * from b_task",con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
}



 

bal.CS

public class bal
{
    dal d = new dal();
    public int save(string name, string mobile)
    {
        return d.save(name, mobile);
    }
}




dal.CS

public class dal
{
    SqlConnection con = new SqlConnection(@"Data Source=SQLDB;Persist Security Info=True;User ID=Demoh;Password=Demo1@");
    DataClassesDataContext dc = new DataClassesDataContext();
    public int save(string name, string mobile)
    {
      return dc.task_ins(name, mobile);

}



StoreProcedure

ALTER PROCEDURE dbo.task_ins
    @name nvarchar(50)=null,
    @mobile nvarchar(50)=null,
    @s nvarchar(10)=null
AS
   
    begin
        insert into b_task values(@name,@mobile)
    end
    if @s='s'
    begin
        select * from b_task
    end
    RETURN