ADO.NET learning experience, "a"

      Hello everyone, I was code-named six hundred and one, am glad they began to restart the blog, in order to better review and deepen their memories, today began to insist to write about their feelings and experiences, just beginning to learn ADO.NET also forced to look ignorant the code will know only beat hands is not difficult, as long as we knock a few times, will naturally understand the secret, ADO.NET in fact the application in C # and ASP.NET MVC project can be, the following is the process of establishing .

the using the System;
 the using the System.Collections.Generic;
 the using the System.Data.SqlClient;
 the using the System.Linq;
 the using the System.Text;
 the using System.Threading.Tasks; 

namespace the ADO.NET connection 
{ 
    class Program 
    { 
        static  void the Main ( String [] args) 
        { 
            // connect to the database steps:
             // 1, create a connection string 
            / * mode 1: Data Source = server name /./Localhost 
             * Initial Cataog = itcast2014; (database name) 
             * Integrated Security = True; (Windows service landing) 
             * Second way:
             * String conn = "Data Source = server name; Initial Catalog = database name; User ID = sa; Password = 123"; // (SQL Service to verify landing) 
             * Three ways: server = server name /./Localhost;database= database name; uid = sa; pwd = 123 ; (SQL Service to verify landing) 
             * / 
            String conn = " the Data Source = WIN-ERSP4OF47I2; Initial Cataog = MyDatabaseOne; SA the User ID =; Password = 016 676 " ;
             // 2, create connection object 
            a using (the SqlConnection connString = new new the SqlConnection (conn)) 
            { 
                // test, open a connection
                 // 3, open the connection (if you open a database connection is not a problem that a connection is successfully!) 
                connString.Open (); 
                Console.WriteLine ( " open database success" ); 
                
                // 4, close the connection, the release of resources
                 // connString.Close (); 

                // connString.Dispose (); 
     
            } 
            Console.WriteLine ( " close the connection, release resources !! " ); 
            the Console.ReadKey (); 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/daihaoliulingyi601/p/11870065.html