11.SqlConnection对象创建的几种写法:  
 2第一种:
 3string connstring = "server=localhost;user id = sa;password=;database=Northwind";
 4SqlConnection mySqlConnection = new SqlConnection();
 5mySqlConnection.ConnectionString =connstring;
 6第二种;
 7SqlConnection myconnection = new SqlConnection("server=localhost;user id =sa;password=;database=Northwind");
 8第三种:
 9string connstring = "server=localhost;user id = sa;password=;database=Northwind";
10SqlConnection mySqlConnection = new SqlConnection(connstring);
11
12--------------------------------------------------------------------------------
13
142.SqlCommand对象创建的几种写法:
15第一种:
16SqlConnection myconnection = new SqlConnection();   
17myconnection.ConnectionString="server=localhost;user id = sa;password=;database=Northwind";
      //  创建并返回一个与SqlConnection关联的SqlCommand对象
18SqlCommand mycommand =myconnection.CreateCommand();
19mycommand.CommandText="Delete From Customers where CustomerID in ";//句号后为省略部份.
20mycommand.ExecuteNonQuery();
21第二种:
22SqlConnection myconnection = new SqlConnection();   
23myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
24SqlCommand mycommand = new  SqlCommand("Delete From Customers where CustomerID in ",myconnection);
25mycommand.ExecuteNonQuery();
26第三种:
27SqlConnection myconnection = new SqlConnection();   
28myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
29string strsql = "Delete From Customers where CustomerID in ";
30SqlCommand mycommand = new  SqlCommand(strsql,myconnection);
31mycommand.ExecuteNonQuery();
32
33--------------------------------------------------------------------------------
34
353.SqlDataAdapter对象创建的几种写法:
36第一种:    文本形式(微软推荐)
37SqlConnection myconnection = new SqlConnection();   
38myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
39SqlDataAdapter mycommand = new SqlDataAdapter("
40Delete From Customers where CustomerID in ","server=localhost;user id = sa;password=;database=Northwind"); 
41
42每二种:    以参数形式(SqlCommand)
43SqlConnection myconnection = new SqlConnection();   
44myconnection.ConnectionString="server=localhost;user id = sa;password=;database=Northwind";
45SqlCommand mycommand = new  SqlCommand("Delete From Customers where CustomerID in ",myconnection);
46SqlDataAdapter mycommand = new SqlDataAdapter(mycommand);
47
48第三种:
49SqlConnection myconnection = new SqlConnection();   
50myconnection.ConnectionString="server=localhost;user id = sa;password=;database=Northwind";
51SqlDataAdapter mycommand = new SqlDataAdapter("Delete From Customers where CustomerID in ",myconnection);
52
53第四种:
54SqlConnection myconnection = new SqlConnection();   
55myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
56string strsql="Delete From Customers where CustomerID in ";
57SqlDataAdapter mycommand = new SqlDataAdapter(strsql,myconnection);
58
59--------------------------------------------------------------------------------
60
614.打开与关闭SqlConnection的几种写法:
62第一种:
63 SqlConnection myconnection = new SqlConnection(); 
64myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
65 SqlCommand mycommand = new SqlCommand("Delete From Customers where CustomerID in ",myconnection);
66mycommand.Connection.open();
67SqlDataReader myreader = mycommand.ExecuteReader();
68mycommand.Connection.close();
69
70第二种:
71 SqlConnection myconnection = new SqlConnection(); 
72myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
73SqlCommand mycommand = new SqlCommand("Delete From Customers where CustomerID in ",myconnection);
74myconnection.open();
75SqlDataReader myreader = mycommand.ExecuteReader();
76myconnection.close();
77
78第三种:
79SqlConnection myconnection = new SqlConnection(); 
80myconnection.ConnectionString ="server=localhost;user id = sa;password=;database=Northwind";
81SqlCommand mycommand = new SqlCommand("Delete From Customers where CustomerID in ",myconnection);
82mycommand.Connection.open();
83SqlDataReader myreader = mycommand.ExecuteReader(CommandBehavior.CloseConnection);