[閒聊]看到使用C#開發ADO.NET的好處...

看板C_Sharp (C#)作者時間20年前 (2004/10/01 15:32), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
最近開發資料庫程式時看到的文件... :P 參考連結: http://www.microsoft.com/taiwan/msdn/library/2003/Jul-2003-tw/adonetbest.htm ================================================================= 在 C# 中使用「using」敘述 對於 C# 開發人員,確保您總是會關閉 Connection 和 DataReader 物件的一個便利方式是使用 using 敘述。using 敘述會在所使用的 物件離開 using 敘述的適用範圍時自動呼叫物件的 Dispose 方法。 例如: //C# string connString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"; using (SqlConnection conn = new SqlConnection(connString)) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT CustomerId, CompanyName FROM Customers"; conn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) Console.WriteLine("{0}\t{1}", dr.GetString(0), dr.GetString(1)); } } -- ※ Origin: 元智大學 風之塔 <bbs.yzu.edu.tw> ※ From : 220-135-222-145.hinet-ip.hinet.net ※ X-Info: [閒聊]看到使用C#開發ADO.NET的好處... ※ X-Sign: 10LQ0UJ9WBZEKwzl9QkA (04/10/01 15:14:27 )

203.203.7.95 10/02, , 1F
VB.NET 2005 也支援 Using 的敘述了
203.203.7.95 10/02, 1F
文章代碼(AID): #11NGVo00 (C_Sharp)
文章代碼(AID): #11NGVo00 (C_Sharp)