C#web Application Primer One of the classic learning notes _ Basic Application

Source: Internet
Author: User
Recently watched the beginning C # WEB applications Wtith Visual Studio. Net. I feel that 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 it out today, and finish it up 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";

Judge User authorization:

Context.User.Identity.IsAuthenticated;

Table Related:

1. Create a new image img
2. IMG Add to Cell
3. Cell Add to Row
4. Row Add 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 the authenticated user back to the originally requested URL

public static void RedirectFromLoginPage (String Username,bool createpersistentcookie);

Parameters
UserName
The name of the user to use for the Cookie authentication. This does not need to be mapped to an account name and will be used by URL authentication.
createPersistentCookie
Specifies whether a persistent cookie should be issued (a cookie saved across a browser session).

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 Reader's read () method to determine whether the value is actually returned

If (reader. Read ())
... {
This.Email.Text = reader["Email"]. ToString ();
}

DataSet Basic Operations
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.