ADO. NET 7-use the Command object to find database records --- ShinePans,

Source: Internet
Author: User

ADO. NET 7-use the Command object to find database records --- ShinePans,

Query the number of data in the data path:


Code:


Using System; using System. collections. generic; using System. data; using System. data. sqlClient; using System. linq; using System. text; using System. threading. tasks; namespace SQLTest {class Program {static void Main (string [] args) {// connect to the database string connection = "server = Pan Shang \ SQLEXPRESS; database = db_test; trusted_Connection = true "; SqlConnection SC = new SqlConnection (connection); SC. connectionString = connecti On; try {SC. Open (); // Open the database connection Console. WriteLine ("the database connection has been enabled! "); SqlCommand cmd = new SqlCommand (" SELECT count (*) FROM db_student ", SC); int I = (int) cmd. executeScalar (); // execute the command Console for searching records. writeLine ("A total of {0} pieces of data in the table", I. toString (); // START: 3. modify the database data code /////////////////////////////////// /// // * SqlCommand cmd = new SqlCommand ("UPDATE db_student SET student_grade = 99 where student_name = @ name ", SC); // create the SqlCommand object cmd. parameters. add ("@ name", SqlDb Type. VarChar). Value = "pan"; int I = cmd. ExecuteNonQuery (); if (I> 0) Console. WriteLine ("modified successfully! "); * // END: 3. modify the database data code /////////////////////////////////// /// // START: 1. delete the database record code segment //////////////////////////////////// //// // * string plain text = "delete from db_student WHERE student_name = @ name "; sqlCommand cmd = new SqlCommand (plain text, SC); cmd. parameters. add ("@ name", SqlDbType. varChar ). value = "pan"; int I = cmd. executeNonQuery (); if (I> 0) Console. writeLine ("the record is deleted successfully.! "); * // END: 1. delete the database record code segment //////////////////////////////////// /// // START: 2. add the recorded code //////////////////////////////////// //// // * SqlCommand cmd = new SqlCommand (); // create the SqlCommand object cmd. commandType = CommandType. text; // set the command to run the command cmd. connection = SC; // set the object property cmd. commandText = "insert into db_student (student_name, student_age, student_address, student_grade) VALUES (@ nam E, @ age, @ address, @ grade) "; // Add a parameter and assign the cmd value to the parameter. parameters. add ("@ name", SqlDbType. varChar, 10 ). value = "pan"; cmd. parameters. add ("@ age", SqlDbType. int ). value = 19; cmd. parameters. add ("@ address", SqlDbType. varChar ). value = "Wuhan"; cmd. parameters. add ("@ grade", SqlDbType. int ). value = 100; int I = cmd. executeNonQuery (); // execute the database add record command if (I> 0) Console. writeLine ("successfully added the record"); * // The console outputs the Add record // END: 2. code for adding a record /////// //////////////////////////////////////// /// //} Catch (Exception ex) {Console. writeLine ("Opening Database Error: {0}", ex. message);} finally {SC. close (); Console. writeLine ("the database connection is closed! ") ;}System. Console. ReadLine ();}}}

Running result:




Brief description of steps for ADONET to access the database

1. Introduce the namespace
2. Define the connection string
3. Define the connection object
4. Write SQL statements
5. Create a command object
6, try {} catch {} finally {}
7. Open the database connection
8. Create a DataReader object.
9. Read the query results of the DataReader object row by row.
0. Close the DataReader object.
11. Close the database connection.

Methods and jobs for connecting the three objects of ADONet to the database

Through the entire teaching process of Web page design and Internet application development courses, students can understand the differences between various Web browsers, the basic features and HTML features of Web pages, and master the use of frequently-used Web page creation tools, this allows you to design websites, develop webpages, master the development methods and processes of Internet-based application systems, and integrate the network knowledge, database system principles, and program design methods, as well as the financial, management, and enterprise planning knowledge, students can plan, deploy, and develop information-based basic platforms and application platforms for enterprises and institutions, and improve the overall quality of students, meeting the needs of future work, and preparing for training information management talents who understand the management and technology levels required for China's socialist modernization. 2. the teaching content and basic requirements mainly involve website construction and composition, the characteristics of HTML source code, the use of development tools, the composition of dynamic web pages, and the education of development methods, it helps students master the characteristics of modern system development based on the B/S mode, and fully master the construction and development process of information systems. chapter 1 Basic website creation knowledge 1. understand the basic features of Web pages 2. measure the test taker's knowledge about the basic steps of creating a webpage, including overall planning, webpage design and production, testing webpages, and uploading and publishing webpages. learn more about common webpage creation tools. 4. understanding common web browser features Chapter 1 HTML basics 1. understand what is HTML 2. understand the HTML tag format 3. understand the page structure, including: Page Structure tag, page header title, and HTML file structure. 4. learn about HTML basic tags, including: Comments, structure tags, titles and page headers, paragraphs, links, lists and character formats, other elements and font sizes 5. understanding image labels 6. understanding form labels 7. understand the framework label 8. learn about table labels 9. understanding character entity labels 10. learn about Internet Explorer label attributes chapter 3rd DreamWeaver MX 20041. understand the basics of DreamWeaver MX, including working environment, HTML code view, document operations, and website construction. learn the basic knowledge and operations of editing pages, including editing text, CSS styles, hyperlink, using images, and using table 3. understand the overall layout knowledge and operations, including: layered positioning, using the framework 4. understand advanced DreamWeaver applications, including using forms, embedding objects, and performing behaviors. measure the test taker's understanding about the basic knowledge and operations of website maintenance. Chapter 4 dynamic website Introduction 1. compare static websites with dynamic websites 2. understand common dynamic website design methods Chapter 1 ASP Overview 1. ASP Introduction 2. introduction to ASP runtime environment chapter 1 ASP script basics 1. script overview, including: Use of the script language, specify the default script language 2. understand server scripts and client scripts. 3. VBScript introduction, including: dividing a single-row statement into multiple rows, adding comments to the code, using numbers, data types, variables, constants, arrays, operations, and control structures of different operating systems, with statement, process, VBscript function Introduction 4. javaScript introduction, including: statements and statement blocks, variables, data types, operators, arrays, control structures, functions, JavaScript objects, copying, passing, and comparing data, special Character Chapter 1 ASP object 1. measure the test taker's understanding about the Request object, including the data set of the Request object, the property of the Request object, and the method of the Request object. understand the Response object, including: Response object method, Response object attribute, and Response object set 3. understand Session objects, including Session overview, Session Object events, Session Object methods, Session object attributes, Session object data sets, and Session object usage Example 4. understand Application objects, including Application object overview, Application Object events, Application Object settings and variable reading, Application Object methods, and Application object data sets. measure the test taker's understanding about Server objects, including the attributes of Server objects. Method 6 of Server objects. learn about Cooki ...... remaining full text>
 

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.