Basic Steps for database operations in ASP. NET

Source: Internet
Author: User

1. Basic Steps for ASP. NET database operations:

Common Methods for ASP. NET data operations:
A. ExecuteReader ()
The returned result is a SqlDataReader object or OleDbDataReader object. Each return or operation guides a record to be stored in the server's memory.
Compared with DataSet, quick access is usually used for query operations.
B. ExecuteNonQuery ()
C. ExecuteScalar () returns the Object type. If SELECT is executed, the returned result is the first column in the first row after the query.
Returns the number of rows affected by the database, which is the first choice for database transaction processing.
Public int test ()
{
String connStr = @ "server = Miro; database = newssystem; uid = sa; pwd = sa ";
SqlConnection conn = new SqlConnection (connStr );
Conn. Open ();
String SQL = "insert into category (name) values ('ttt ')";
SqlCommand cmd = new SqlCommand (SQL, conn );
Int res = cmd. ExecuteNonQuery ();
Conn. Close ();
Return res;
}
Public DataTable test (string SQL)
{
DataTable dt = new DataTable ();
String connStr = @ "server = Miro; database = newssystem; uid = sa; pwd = sa ";
SqlConnection conn = new SqlConnection (connStr );
Conn. Open ();
SqlCommand cmd = new SqlCommand (SQL, conn );
SqlDataReader sdr = cmd. ExecuteReader ();
Dt. Load (sdr );
Sdr. Close ();
Conn. Close ();
Return dt;
}
2. Tips for:
You can add the tool --> Custom --> command --> debugging to the toolbar without debugging.

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.