private void ThreeMethod() { NorthwindDataContext ctx = new NorthwindDataContext(constr); GridView3.DataSource = from c in ctx.Customers select new { 顾客编号 = c.Id, 顾客姓名 = c.Name, 所在地 = c.City }; GridView3.DataBind(); }
/// <summary> /// 执行查询 /// </summary> private void ExecuteQuery() { NorthwindDataContext ctx = new NorthwindDataContext(ConnectionString); string newName = "李四"; ctx.ExecuteCommand("update Customer set City={0} where Id like 'A%'", newName); IEnumerable <Customer> customers = ctx.ExecuteQuery <Customer>("SELECT * FROM dbo.Customer WHERE Id LIKE 'A%';"); GridView5.DataSource = customers; GridView5.DataBind(); }
/// <summary> /// 日志功能 /// </summary> private void LogMethod() { NorthwindDataContext ctx = new NorthwindDataContext(constr); StreamWriter sw = new StreamWriter(Server.MapPath("../../Log/log.txt"), true); ctx.Log = sw; GridView4.DataSource = from c in ctx.Customers select new { 顾客编号 = c.Id, 顾客姓名 = c.Name, 所在地 = c.City }; GridView4.DataBind(); sw.Close(); }