I recently read "Beginning C# Web Applications Wtith Visual Studio .Net". I feel that this book is well written in some details, so I took notes to provide some things that may be useful to those who come after me. I’ll write some down today and finish them correctly before the year.
Current date:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
Determine user authorization:
Context.User.Identity.IsAuthenticated;
Form related:
1. Create a new image img
2. Add img to cell
3. Add cell to row
4. Row added to Table
5. Table added to 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);
Redirect authenticated users back to the originally requested URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
Parameters
userName
User name used for cookie authentication. This does not need to be mapped to an account name and will be used by URL authentication
createPersistentCookie
Specifies whether persistent cookies should be issued (cross-browsing). Cookie saved by the server session)
Standard database operation 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();
Standard database operation 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();
Can be judged by the reader's Read() method. Whether the value is really returned
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”);
The above is the detailed content of Introduction to C# Web Applications Classic Notes (Volume 1). For more information, please follow other related articles on the PHP Chinese website!