使用linq链接asp点网?

时间:2013-02-20 04:48:30

标签: c# asp.net linq hyperlink

这是我的代码:

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

public partial class First : System.Web.UI.Page
{ MyDataClassesDataContext mdc;


protected void Page_Load(object sender, EventArgs e)
{
    mdc = new MyDataClassesDataContext();
    if (!IsPostBack)
    {
        LoadData();
    }
}

private void LoadData()
{
    mdc = new MyDataClassesDataContext();
    var empls = from em in mdc.Emps select em;

    GVEmp.DataSource = empls;
    GVEmp.DataBind();

    var ddlempls = from em in mdc.Emps
            select new
            {
                em.EmpID,
                em.Ename
            };

    DDLEmp.DataSource = ddlempls;
    DDLEmp.DataTextField = "Ename";
    DDLEmp.DataValueField = "EmpID";
    DDLEmp.DataBind();
    DDLEmp.Items.Insert(0, "Select");
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
    Emp em = new Emp();
    em.Ename = TxtName.Text;
    em.Sal = Int32.Parse(TxtSal.Text);

    mdc.Emps.InsertOnSubmit(em);
    mdc.SubmitChanges();
    LoadData();
    LabDisp.Text = "Record Added";
}
protected void DDLEmp_SelectedIndexChanged(object sender, EventArgs e)
{ Emp empl = mdc.Emps.Single(em => em.EmpID ==Int32.Parse(DDLEmp.SelectedItem.Value));

    if (empl != null)
    {
        TxtName0.Text = empl.Ename;
        TxtSal0.Text = empl.Sal.ToString();
    }
    else
    {
        LabDisp.Text = "Data not found";
    }
}
protected void LBUpd_Click(object sender, EventArgs e)
{
 Emp empl = mdc.Emps.Single(em => em.EmpID ==Int32.Parse(DDLEmp.SelectedItem.Value));

    if (empl != null)
    {
        empl.Ename = TxtName0.Text;
        empl.Sal=Int32.Parse(TxtSal0.Text);
        mdc.SubmitChanges();
        LoadData();
        LabDisp.Text = "record updated";
    }
    else
    {
        LabDisp.Text = "Data not found";
    }
}
protected void LBDel_Click(object sender, EventArgs e)
{
 Emp empl = mdc.Emps.Single(em => em.EmpID == Int32.Parse(DDLEmp.SelectedItem.Value));

    if (empl != null)
    {
        mdc.Emps.DeleteOnSubmit(empl);
        mdc.SubmitChanges();
        LoadData();
        LabDisp.Text = "record deleted";
    }
    else
    {
        LabDisp.Text = "Data not found";
    }
}
}

任何人都可以帮助和解释这个代码...我的一个朋友发送这个和   一个配置文件给我链接一个asp页面与数据库..有一些像MyDataClassesDataContext,GVEmp.DataSource这些对我来说很新,我不理解其中任何一个

1 个答案:

答案 0 :(得分:0)

看起来代码正在使用EntityFrameWork或Linq2SQL左右......这些链接可能会有所帮助

阅读这些工具