C#Web應(yīng)用程序入門經(jīng)典學(xué)習(xí)筆記之一
更新時(shí)間:2006年08月15日 00:00:00 作者:
最近看了《Beginning C# Web Applications Wtith Visual Studio .Net 》。感覺這本書在一些細(xì)節(jié)方面寫的不錯(cuò),特做筆記,為后來者提供一些或許有用的東東。今天先寫出來一些,年前正確整理完。
當(dāng)前日期:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
判斷用戶授權(quán):
Context.User.Identity.IsAuthenticated;
表格相關(guān):
1. 新建一圖片img
2. img添加到cell
3. cell添加到row
4. row添加到Table
5. Table添加到PlaceHolder
Table tb = new Table();
TableRow row = new TableRow();
Image img = new Image();
img.ImageUrl = "Images/winbook.gif";
img.ImageAlign = ImageAlign.Middle;
img.Width = new Unit(24, UnitType.Pixel);
img.Height = new Unit(24, UnitType.Pixel);
cell = new TableCell();
cell.Controls.Add(img);
row.Cells.Add(cell);
HyperLink lnk = new HyperLink();
lnk.Text = "News";
lnk.NavigateUrl = "News.aspx";
row.Cells.Add(cell);
tb.Rows.Add(row);
phNav.Controls.Add(tb);
將已驗(yàn)證身份的用戶重定向回最初請(qǐng)求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
參數(shù)
userName
用于 Cookie 身份驗(yàn)證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗(yàn)證使用。
createPersistentCookie
指定是否應(yīng)當(dāng)發(fā)出持久性 Cookie(跨瀏覽器會(huì)話保存的 Cookie)。
標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)操作1
String sql;
SqlCommand cmd;
SqlConnection conn;
Sql = “insert into …”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”);
cmd = new SqlCommand (sql,conn);
conn.open();
cmd.ExecuteNonQuery();
標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)操作2
SqlConnection conn;
SqlCommand cmd;
SqlDataReader reader;
string sql;
sql = “select * from TableName”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
cmd = new SqlCommand(sql,conn);
conn.open();
reader = cmd.ExecuteReader();
可以用reader的Read()方法判斷是否真的返回了值
If (reader.Read())
...{
This.Email.Text = reader[“Email”].ToString();
}
DataSet 基本操作
DataSet dsCaoxicao;
String sql;
SqlConnection conn;
SqlDataAdapter adPlaces;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
adPlaces = new SqlDataAdapter(sql,conn);
dsCaoxiCao = new DataSet();
conn.Open();
adPlaces.Fill(dsCaoxiCao,”Places”);
當(dāng)前日期:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
判斷用戶授權(quán):
Context.User.Identity.IsAuthenticated;
表格相關(guān):
1. 新建一圖片img
2. img添加到cell
3. cell添加到row
4. row添加到Table
5. Table添加到PlaceHolder
Table tb = new Table();
TableRow row = new TableRow();
Image img = new Image();
img.ImageUrl = "Images/winbook.gif";
img.ImageAlign = ImageAlign.Middle;
img.Width = new Unit(24, UnitType.Pixel);
img.Height = new Unit(24, UnitType.Pixel);
cell = new TableCell();
cell.Controls.Add(img);
row.Cells.Add(cell);
HyperLink lnk = new HyperLink();
lnk.Text = "News";
lnk.NavigateUrl = "News.aspx";
row.Cells.Add(cell);
tb.Rows.Add(row);
phNav.Controls.Add(tb);
將已驗(yàn)證身份的用戶重定向回最初請(qǐng)求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
參數(shù)
userName
用于 Cookie 身份驗(yàn)證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗(yàn)證使用。
createPersistentCookie
指定是否應(yīng)當(dāng)發(fā)出持久性 Cookie(跨瀏覽器會(huì)話保存的 Cookie)。
標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)操作1
String sql;
SqlCommand cmd;
SqlConnection conn;
Sql = “insert into …”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”);
cmd = new SqlCommand (sql,conn);
conn.open();
cmd.ExecuteNonQuery();
標(biāo)準(zhǔn)數(shù)據(jù)庫(kù)操作2
SqlConnection conn;
SqlCommand cmd;
SqlDataReader reader;
string sql;
sql = “select * from TableName”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
cmd = new SqlCommand(sql,conn);
conn.open();
reader = cmd.ExecuteReader();
可以用reader的Read()方法判斷是否真的返回了值
If (reader.Read())
...{
This.Email.Text = reader[“Email”].ToString();
}
DataSet 基本操作
DataSet dsCaoxicao;
String sql;
SqlConnection conn;
SqlDataAdapter adPlaces;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
adPlaces = new SqlDataAdapter(sql,conn);
dsCaoxiCao = new DataSet();
conn.Open();
adPlaces.Fill(dsCaoxiCao,”Places”);
您可能感興趣的文章:
- C#向無窗口的進(jìn)程發(fā)送消息
- C#微信開發(fā)之接收 / 返回文本消息
- C#實(shí)現(xiàn)帶消息數(shù)的App圖標(biāo)
- C#記錄消息到日志文件的方法
- C# WinForm應(yīng)用程序降低系統(tǒng)內(nèi)存占用方法總結(jié)
- c#取得控制臺(tái)應(yīng)用程序根目錄
- C# 禁止應(yīng)用程序多次啟動(dòng)的實(shí)例
- C#Web應(yīng)用程序入門經(jīng)典學(xué)習(xí)筆記之二
- C#實(shí)現(xiàn)將應(yīng)用程序設(shè)置為開機(jī)啟動(dòng)的方法
- C#使用windows服務(wù)開啟應(yīng)用程序的方法
- C#實(shí)現(xiàn)在應(yīng)用程序間發(fā)送消息的方法示例
相關(guān)文章
.Net?6簡(jiǎn)介并和之前版本寫法做對(duì)比
這篇文章介紹了.Net?6簡(jiǎn)介并和之前版本寫法做對(duì)比,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
Blazor實(shí)現(xiàn)數(shù)據(jù)驗(yàn)證
這篇文章介紹了Blazor實(shí)現(xiàn)數(shù)據(jù)驗(yàn)證的方式,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01
.Net報(bào)表開發(fā)控件XtraReport介紹
這篇文章介紹了.Net報(bào)表開發(fā)控件XtraReport,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
.Net中Task Parallel Library的基本用法
這篇文章介紹了.Net中Task Parallel Library的基本用法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10
利用C#遠(yuǎn)程存取Access數(shù)據(jù)庫(kù)
目前,基于數(shù)據(jù)庫(kù)服務(wù)器的桌面管理程序和Web程序已經(jīng)有太多的應(yīng)用了,尤其是網(wǎng)絡(luò)的大量普及,孤立地?cái)?shù)據(jù)庫(kù)管理系統(tǒng)無法勝任分布式管理應(yīng)用,但是面對(duì)基于Access數(shù)據(jù)庫(kù)的現(xiàn)有的桌面應(yīng)用我們也無法完全的摒棄。我們利用.Net 遠(yuǎn)程處理功能將連接和存取Access的行為封裝為一個(gè)遠(yuǎn)程對(duì)象,供網(wǎng)絡(luò)中其它客戶端通過調(diào)用該遠(yuǎn)程對(duì)象來存取實(shí)際的Access數(shù)據(jù)庫(kù)。我們以 C# 2005 為開發(fā)語言來實(shí)現(xiàn)上述功能。2008-04-04

