C#winfrom minimalist Dbhelp (database connection operation)

Source: Internet
Author: User

The code is as follows:

//need to reference a namespaceusingSystem.Data;usingSystem.Data.SqlClient; classDBHelper {//Define database connection statements, connection statement writing method reference (end of article)         Public Static stringConnStr ="Data Source=.;i Nitial catalog=mobiledb;integrated security=true"; //Create a database connection object          Public StaticSqlConnection conn =NewSqlConnection (CONNSTR); //Define the DataTable Query method and return to table         Public StaticDataTable getdatatable (stringsqlstr) {            //Create a Databale objectDataTable table =NewDataTable (); //creating an Adapter objectSqlDataAdapter ADP =NewSqlDataAdapter (SQLSTR, Conn); //Data PopulationADP.            Fill (table); returntable; }        //define methods to perform additions, deletions and changes         Public Static BOOLExecuteNonQuery (stringsqlstr) {             //Open a database connectionConn.            Open (); //Create a Command object and execute the SQL statementSqlCommand cmd =NewSqlCommand (SQLSTR, conn); intresult =cmd.            ExecuteNonQuery (); //Close ConnectionConn.            Close (); //Defining return Values            returnResult >0; }    }

*sql database two connection strings

    1. SQL Server Authentication Login: Server = Server name ;d atabase= Database name ; uid= User name ;p wd= Password ;

    2. Windows Authentication Connection string: serve= server name; database= Database name ; Integrated security=true;

C#winfrom minimalist Dbhelp (database connection operation)

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.