新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
學(xué)習(xí)LINQ基本操作的一點(diǎn)體會
學(xué)習(xí)LINQ基本操作 ,其實(shí)主要就是LINQ更新、插入以及刪除的相關(guān)操作,那么具體的實(shí)現(xiàn)過程是什么呢?我們在具體的過程中需要注意什么呢?網(wǎng)上有很多資料,這里向你介紹一些,希望對你有所幫助。

LINQ基本操作學(xué)習(xí)1.
我首先創(chuàng)建一個(gè)表,名字為:userinfo的表。
LINQ基本操作學(xué)習(xí)2.
將表拉到vs 2008的linq file上面,然后保存一下,你會看到如下圖,ms利用拖放式方法,生成表對應(yīng)的類,這個(gè)比nhibername方便多了。只要你一保存它就會自動自成一個(gè)class。
LINQ基本操作學(xué)習(xí)3.編寫代碼:
LINQ基本操作代碼如下:
- public partial class TestLinQ_Default : System.Web.UI.Page
- ...{
- GetUserInfoDataContext cxt =
- new GetUserInfoDataContext(
- System.Configuration.ConfigurationManager.
- ConnectionStrings["TestConnectionString"].ToString());
- protected void Page_Load(object sender, EventArgs e)
- ...{
- }
- //LINQ基本操作插入操作
- protected void Button1_Click(object sender, EventArgs e)
- en_Text'').style.display=''inline'';" align="top" alt=""
- src="http://images.csdn.net/syntaxhighlighting/
- OutliningIndicators/ContractedSubBlock.gif" />...{
- UserInfo userinfo = new UserInfo();
- userinfo.username = TextBox1.Text;
- userinfo.password = TextBox2.Text;
- cxt.UserInfos.InsertOnSubmit(userinfo);
- cxt.SubmitChanges();
- // cxt.InsertUserInfo(TextBox1.Text, TextBox2.Text);
- }
- //LINQ基本操作之刪除操作
- protected void Button2_Click(object sender, EventArgs e)
- ...{
- UserInfo userinfo =
- cxt.UserInfos.Single(b => b.id == int.Parse(txt_id.Text));
- cxt.UserInfos.DeleteOnSubmit(userinfo);
- cxt.SubmitChanges();
- }
- //LINQ基本操作之更新操作protected void Button3_Click(object sender, EventArgs e)
- splay=''inline'';
- document.getElementById(''_947_1210_Closed_Text'').
- style.display=''inline'';" align="top" alt="" src=
- "http://images.csdn.net/syntaxhighlighting/
- OutliningIndicators/ExpandedSubBlockStart.gif" />...{
- UserInfo userinfo =
- cxt.UserInfos.Single(b => b.id ==
- int.Parse(txt_update_id.Text));
- userinfo.username = txt_update_username.Text;
- userinfo.password = txt_update_password.Text;
- // cxt.UserInfos.
- cxt.SubmitChanges();
- }
- }
LINQ基本操作學(xué)習(xí)的一些內(nèi)容就向你介紹到這里,希望對你了解和學(xué)習(xí)LINQ基本操作有所幫助。
【編輯推薦】
- 詳解實(shí)現(xiàn)LINQ to SQL刪除行
- C# Lambda Expression概念淺析
- 詳解C# Lambda表達(dá)式的動態(tài)生成
- C# Lambda Expression使用實(shí)例解析
- 淺談LINQ刪除XML節(jié)點(diǎn)
分享標(biāo)題:學(xué)習(xí)LINQ基本操作的一點(diǎn)體會
當(dāng)前網(wǎng)址:http://www.5511xx.com/article/dpjhpos.html


咨詢
建站咨詢
