C#Web應用程序入門經(jīng)典學習筆記之一
更新時間:2006年08月15日 00:00:00 作者:
最近看了《Beginning C# Web Applications Wtith Visual Studio .Net 》。感覺這本書在一些細節(jié)方面寫的不錯,特做筆記,為后來者提供一些或許有用的東東。今天先寫出來一些,年前正確整理完。
當前日期:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
判斷用戶授權:
Context.User.Identity.IsAuthenticated;
表格相關:
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);
將已驗證身份的用戶重定向回最初請求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
參數(shù)
userName
用于 Cookie 身份驗證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗證使用。
createPersistentCookie
指定是否應當發(fā)出持久性 Cookie(跨瀏覽器會話保存的 Cookie)。
標準數(shù)據(jù)庫操作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();
標準數(shù)據(jù)庫操作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”);
當前日期:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
判斷用戶授權:
Context.User.Identity.IsAuthenticated;
表格相關:
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);
將已驗證身份的用戶重定向回最初請求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
參數(shù)
userName
用于 Cookie 身份驗證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗證使用。
createPersistentCookie
指定是否應當發(fā)出持久性 Cookie(跨瀏覽器會話保存的 Cookie)。
標準數(shù)據(jù)庫操作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();
標準數(shù)據(jù)庫操作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”);
相關文章
Entity Framework系統(tǒng)架構與原理介紹
這篇文章介紹了Entity Framework系統(tǒng)架構與原理,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-03-03.Net行為型設計模式之模板方法模式(Template?Method)
這篇文章介紹了.Net行為型設計模式之模板方法模式(Template?Method),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05ASP.NET2.0+SQL Server2005構建多層應用
ASP.NET2.0+SQL Server2005構建多層應用...2006-12-12連接ACCESS數(shù)據(jù)庫時發(fā)生錯誤提示:找不到可安裝的 ISAM
連接ACCESS數(shù)據(jù)庫時發(fā)生錯誤提示:找不到可安裝的 ISAM 檢查后發(fā)現(xiàn)原來是把Data Source寫成 DataSource了2011-04-04使用vs2022在.net6中調(diào)試帶typescript的靜態(tài)頁面
這篇文章介紹了使用vs2022在.net6中調(diào)試帶typescript的靜態(tài)頁面,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-12-12.Net創(chuàng)建型設計模式之原型模式(Prototype)
這篇文章介紹了.Net設計模式之原型模式(Prototype),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05