C # ADO Base query How many rows of data in a table are in a table in Sqlsever

Source: Internet
Author: User

Town Field Poem:
Cheng listens to the Tathagata language, the world name and benefit of Dayton. Be willing to do the Tibetan apostles, the broad show is by Sanfu mention.
I would like to do what I learned, to achieve a conscience blog. May all the Yimeimei, reproduce the wisdom of the body.
——————————————————————————————————————————

1 Show My sql:


2 Code

First base. cs file

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceShujuku8 {9     classsqlinformationTen     { One         /// <summary> A         ///name of the server -         /// </summary> -          Public stringDataSource; the         /// <summary> -         ///name of the database -         /// </summary> -          Public stringInitialCatalog; +         /// <summary> -         ///true to use Windows authentication +         /// </summary> A          Public BOOLintegratedsecurity; at         /// <summary> -         ///user name required for SQL Server Authentication -         /// </summary> -          Public stringUserID; -         /// <summary> -         ///password required for SQL Server Authentication in         /// </summary> -          Public stringPassword; to         /// <summary> +         ///returns the connection string -         /// </summary> the          Publicsqlinformation () *         { $IntegratedSecurity =false;Panax Notoginseng         } -          Public stringlogininformation () the         { +             if(integratedsecurity) A             { the                 return string. Format (@"Data Source = {0}; Initial Catalog = {1}; Integrated Security = True", DataSource, initialcatalog); +             } -             Else $             { $                 return string. Format (@"Data Source = {0};initial Catalog = {1}; User ID = {2}; Password = {3}", DataSource, InitialCatalog, UserID, Password); -             } -         } the     } -}

Second. cs file

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Data.SqlClient;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceShujuku9 {Ten     class Program One     { A         Static voidMain (string[] args) -         { -Sqlinformation test =Newsqlinformation (); theTest. DataSource ="user-20170116mg"; -Test. InitialCatalog ="HelloWorld"; -Test. IntegratedSecurity =true; -             stringConstr=test. Logininformation (); +  -             using(SqlConnection connection =NewSqlConnection (constr)) +             { A                 //write the SQL statement (you can create a script in SQL Server after the attempt succeeds, copy and paste) at                 stringsql ="Select COUNT (*) from Teacherclass"; -                 //create an object that executes an SQL statement -                 using(varcmd =NewSqlCommand ()) -                 { -Cmd.commandtext =SQL; -Cmd. Connection =connection; in                     //Open Connection - connection. Open (); toConsole.WriteLine ("Database Connection succeeded"); +                     intCount =Convert.ToInt32 (cmd. ExecuteScalar ()); -Console.WriteLine ("table Data total: {0} rows", count); theConsole.WriteLine ("SQL statement execution succeeded"); *                 } $                 //closes the connection, freeing the resource. Because of the using, so there is no need to write a statementPanax Notoginseng             } -Console.WriteLine ("Database fractured successfully"); the Console.readkey (); +  A         } the     } +}

3 Result:

Console


——————————————————————————————————————————
The essence of the blog, in the technical part, more in the town yard a poem. Version: VS2015 SqlServer2014 system: Windows 7
C # is a good language, worth studying hard. I'm learning from the. NET video tutorials of the Smart podcast, The Dark Horse.
If the content of the post can be improved, or even the wrong place, please leave a comment, I will try to correct, strive to cast a conscience blog.
Note: This article is only as a scientific research study, if I inadvertently violated your rights and interests, please be sure to timely inform, I will make corrections.

C # ADO Base query How many rows of data in a table are in a table in Sqlsever

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.