Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用linq实现asp.net的链接?_C#_Asp.net_Linq_Hyperlink - Fatal编程技术网

C# 用linq实现asp.net的链接?

C# 用linq实现asp.net的链接?,c#,asp.net,linq,hyperlink,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_

这是我的密码:

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
对我来说是非常新的,我不理解这些东西中的任何一个

看起来代码使用的是EntityFrameWork或LinqSQL等等。。。这些链接可能会有所帮助


阅读这些工具

很抱歉,解释大量代码并不是本网站的目的。如果你对C#和Linq感兴趣,那么你应该尝试很多博客、书籍和其他资源。当你有一个关于编码问题的非常具体且经过充分研究的问题时,可以询问Stack Overflow,我们很乐意提供帮助。