-6
這裏是我的代碼:使用linq連接asp點網絡?
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頁面database..there是鏈接像MyDataClassesDataContext,GVEmp.DataSource
某些事情,這是非常新的給我,我不明白其中的任何
我很抱歉,但解釋的代碼大塊是不是這個網站的目的,閱讀起來。如果您瞭解C#和Linq的興趣,那麼您應該嘗試使用許多博客,書籍和其他資源。當你有一個關於編碼問題的*非常具體的*和經過深入研究的問題時,詢問堆棧溢出,我們將很樂意提供幫助。 – 2013-02-20 05:00:53