Posted on 2008-01-04 21:00
玄铁剑 阅读(359)
评论(0) 编辑 收藏 引用 所属分类:
LinQ
public partial class _Default : System.Web.UI.Page
{
DataContextDb ctx = new DataContextDb("server=xxx;database=TestDb;uid=xxx;pwd=xxx"); protected void
Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindView();
}
}
protected void btnOP_Click(object sender, EventArgs e)
{
//ctx.Log = Console.Out;
tbData tbgb = new tbData();
tbgb .UserName = 'Test001';
//Add
ctx.tbData .Add(tbgb );
//Edit
ctx.tbData.Remove(tbgb);
ctx.SubmitChanges();//Add/Edit or Not Add/Edit==>Modify
BindView();
}
private void SetBind()
{
GridData.DataSource = from gb in ctx.tbData;
GridData.DataBind();
}
}