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

LINQ基本操作學(xué)習(xí)1.
我首先創(chuàng)建一個(gè)表,名字為:userinfo的表。
LINQ基本操作學(xué)習(xí)2.
將表拉到vs 2008的linq file上面,然后保存一下,你會(huì)看到如下圖,ms利用拖放式方法,生成表對(duì)應(yīng)的類,這個(gè)比nhibername方便多了。只要你一保存它就會(huì)自動(dòng)自成一個(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)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)LINQ基本操作有所幫助。
【編輯推薦】
- 詳解實(shí)現(xiàn)LINQ to SQL刪除行
- C# Lambda Expression概念淺析
- 詳解C# Lambda表達(dá)式的動(dòng)態(tài)生成
- C# Lambda Expression使用實(shí)例解析
- 淺談LINQ刪除XML節(jié)點(diǎn)
本文名稱:學(xué)習(xí)LINQ基本操作的一點(diǎn)體會(huì)
轉(zhuǎn)載源于:http://www.dlmjj.cn/article/dpjhpos.html
其他資訊
- 如何使用n點(diǎn)虛擬主機(jī)管理系統(tǒng),n點(diǎn)虛擬主機(jī)管理系統(tǒng)的特點(diǎn)和優(yōu)勢(shì)
- Linux服務(wù)器環(huán)境搭建:讓你輕松上手(linux服務(wù)器環(huán)境搭建)
- DMIT和BlueHost香港主機(jī)簡(jiǎn)單對(duì)比評(píng)測(cè)(bluehost香港主機(jī)很慢)
- Redis監(jiān)測(cè)確保數(shù)據(jù)的有效性(redis監(jiān)測(cè)過期數(shù)據(jù))
- 什么叫服務(wù)器主機(jī)?服務(wù)器賣主機(jī)


咨詢
建站咨詢
