26 Asp. Net detail questions and tips

Source: Internet
Author: User

  Fire Station Building Institute (Bkjia.com) Network ProgrammingToday, I found a collection of asp.net skills while hanging out on a well-known blog, so I couldn't help but reprint it to everyone. I hope my friends like it. It's all about detail-based skills.

1. Differences between <% =... %> and <% #... %>:

A: <% =... %> is called when the program is executed. <% #... %> is called after the DataBind () method.

2. What types of data does the control receive?

A: controls that receive Bind, including DropDownList, DataList, DataGrid, and ListBox, which are mainly associated with ArrayList and Hashtable ), dataView (data view) and DataReader can be seated in the future without the error that the able is bundled :)

3. The data obtained by DataBind will be converted to another type by default as String?

DataBinder. Eval (Container. DataItem, "Conversion Type", "format ")

The last "format" is optional. Generally, you do not need to worry about it. Container. DataItem is a bundled data item. "Conversion Type" refers to Integer, String, Boolean.

4. Main namespace:

<% @ Import Namespace = "System. Data" %> used to process Data

<% @ Import Namespace = "System. Data. ADO" %> used when using ADO.net;

<% @ Import Namespace = "System. Data. SQL" %> dedicated to SQL Server databases

<% @ Import Namespace = "System. Data. XML" %> you do not need to view

<% @ Import Namespace = "System. IO" %> used for File Processing

<% @ Import Namespace = "System. Web. Util" %>

<% @ Import Namespace = "System. Text" %> used for Text Encoding

5. common attributes and methods of Connections (SQLConection or ADOConnection:

| ConnectionString: gets or sets the database connection statement.

| ConnectionTimeout: gets or sets the maximum time for connecting to the database, which is also the timeout time.

| DataBase gets or sets the name of the DataBase to be opened on the DataBase server

| DataSource: Get or set DSN. No stranger to everyone :)

| Password

| UserID: Get or set the login name

| State: gets the current join State.

| Open () Open the connection

| Close () Close the connection

| Clone (): Clone a join. (Hehe, the sheep can connect or I can)

Example:

SQLConnection myConnection = new SQLConnection ();

MyConnection. DataSource = "mySQLServer ";

MyConnection. Password = "";

MyConnection. UserID = "sa ";

MyConnection. ConnectionTimeout = 30;

MyConnection. Open ();

MyConnection. Database = "northwind ";

MyConnection. IsolationLevel = IsolationLevel. ReadCommitted

6. common methods and attributes of Command

| ActiveConnection

| Name of the SQL statement or stored procedure (StoredProcedure) executed by CommandText

| Maximum CommandTimeout execution time

| CommandType Command operation types (StoredProcedure, Text, TableDirect). The default value is Text.

| Parameters

| Execute () Execute SQL statements or stored procedures

| ExecuteNonQuery () is the same as above. The difference is that the record set is not returned.

| Clone () Clone Command

Example:

String mySelectQuery = "SELECT * FROM Categories order by CategoryID ";

StringmyConnectString = "userid = sa; password =; database = northwind; server = mySQLServer ";

SQLCommand myCommand = new SQLCommand (mySelectQuery );

MyCommand. ActiveConnection = new SQLConnection (myConnectString );

MyCommand. CommandTimeout = 15;

MyCommand. CommandType = CommandType. Text; </FONT>

 

7. You can open or close a database in either of the following ways:

1. MyConnection. Open (); // Open the connection

MyConnection. Close ();

2. MyCommand. ActiveConnection. Open ();

MyCommand. ActiveConnection. Close ()

  • Four pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • 4
  • Next Page

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.