C#web app Getting Started classic notes (previous book)

Source: Internet
Author: User
Recently saw Beginning C # Web applications Wtith Visual Studio. Net. I feel this book is good in some detail, special notes, for the latter to provide some of the things that may be useful. Let's write some of them today and finish them correctly years ago.

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

To determine user authorization:

Context.User.Identity.IsAuthenticated;

Table Related:

1. Create a new image img
2. IMG Added to cell
3. Cell added 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 (unittype.pixel); Img. Height = new Unit (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
The user name used for Cookie authentication. This does not need to be mapped to the account name and will be used by URL authentication.
createPersistentCookie
Specifies whether persistent cookies should be issued (cookies saved across browser sessions).

Standard database Operations 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 Operations 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 ();

You can use the Read () method of reader to determine if a value is actually returned

if (reader. Read ()) ... {This.Email.Text = reader["Email"]. ToString (); } DataSet basic Operation 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"); 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.