ASP. NET skills (Collection)

Source: Internet
Author: User

1. Is there a way to make JavaScript comments invisible on the client? The answer is simple: javascript comments + server comments!

Line comment:

// <% -- Write a line comment here -- %>
Block comment writing:

/* <% --
Write the comment statement block here,
Multiple rows.
-- %> */

Our own developers can read the complete annotations, And the compiled ASP.. NET page will ignore the comments in <% -- to -- %>. Malicious attackers will not see these comments on the client. You can only see: // or /**/
2. C # the fastest way to retain N decimal places
. Tostring ("FN ")
Replace N with a number. For example, tostring ("F2") can retain two decimal places, which is quite convenient.
3. Obtain the database connection information in the configuration section.

Code
StringConnstring= String . Empty;
Connectionstringsettings settings=Configurationmanager. connectionstrings ["Databaseconnection"
];
 If(Settings! = Null
)
{
Connstring=
Settings. connectionstring;
}

4. operate databases

Code
Public Dataset executedataset ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection =   New Sqlconnection (connectionstring ))
{
Dataset DS =   New Dataset ();
Sqldataadapter da =   New Sqldataadapter (SQL, connectionstring );
Da. Fill (DS );
Return DS;
}
}

Public   Int Executenonquery ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection =   New Sqlconnection (connectionstring ))
{
Connection. open ();
Sqlcommand cmd =   New Sqlcommand (SQL, connection );

ReturnCmd. executenonquery ();
}
}

Public   Object Executescalar ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection =   New Sqlconnection (connectionstring ))
{
Connection. open ();
Sqlcommand cmd =   New Sqlcommand (SQL, connection );

ReturnCmd. executescalar ();
}
}

5. modify configuration information

Code
Public   Void Saveconfig ( String Key, String Value)
{
Try
{
String Filename =   " Web. config " ;
Xmldocument document =   New Xmldocument ();
Document. Load (filename );
(Xmlelement) document. selectsinglenode ( @" // Deleetting/Add [@ key =' "   + Key +   " '] " ). Setattribute ( " Value " , Value );
Document. Save (filename );
}
Catch (Exception ex)
{
Throw   New Exception (ex. Message );
}
}
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.