學習LINQ基本操作的一點體會
作者:佚名
學習LINQ基本操作其實就是學習LINQ的插入、刪除以及更新的相關操作,那么具體的實現以及需要注意的是什么呢?那么本文就向你介紹詳細的內容。
學習LINQ基本操作 ,其實主要就是LINQ更新、插入以及刪除的相關操作,那么具體的實現過程是什么呢?我們在具體的過程中需要注意什么呢?網上有很多資料,這里向你介紹一些,希望對你有所幫助。
LINQ基本操作學習1.
我首先創建一個表,名字為:userinfo的表。
LINQ基本操作學習2.
將表拉到vs 2008的linq file上面,然后保存一下,你會看到如下圖,ms利用拖放式方法,生成表對應的類,這個比nhibername方便多了。只要你一保存它就會自動自成一個class。
LINQ基本操作學習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基本操作學習的一些內容就向你介紹到這里,希望對你了解和學習LINQ基本操作有所幫助。
【編輯推薦】
責任編輯:仲衡
來源:
diybl.com