国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

C#Web應用程序入門經典學習筆記之一

2024-07-10 13:13:24
字體:
來源:轉載
供稿:網友
最近看了《Beginning C# Web Applications Wtith Visual Studio .Net 》。感覺這本書在一些細節方面寫的不錯,特做筆記,為后來者提供一些或許有用的東東。今天先寫出來一些,年前正確整理完。 

當前日期: 

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); 

參數 
userName 
用于 Cookie 身份驗證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗證使用。 
createPersistentCookie 
指定是否應當發出持久性 Cookie(跨瀏覽器會話保存的 Cookie)。 

標準數據庫操作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(); 

標準數據庫操作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”); 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 闸北区| 汾西县| 塘沽区| 井冈山市| 宣城市| 泗洪县| 阳朔县| 砚山县| 兖州市| 阿瓦提县| 民和| 荆州市| 大渡口区| 清原| 出国| 叶城县| 铜山县| 衡南县| 江安县| 平武县| 澄城县| 内丘县| 南木林县| 黄陵县| 太谷县| 巴东县| 江阴市| 平凉市| 南靖县| 攀枝花市| 固阳县| 海城市| 台南市| 涟源市| 怀集县| 清水河县| 合水县| 建水县| 诸城市| 吐鲁番市| 霞浦县|