玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

Linq数据操作

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();
    }

}

只有注册用户登录后才能发表评论。