- 最後登錄
- 2023-5-13
- 在線時間
- 0 小時
- 註冊時間
- 2007-11-8
- 閱讀權限
- 20
- 精華
- 0
- UID
- 2735771
- 帖子
- 1399
- 積分
- 206 點
- 潛水值
- 17114 米
| 若對尊貴或贊助會員有任何疑問,歡迎向我們查詢。我們的即時通或MSN: admin@eyny.com 本帖最後由 soccertw 於 2014-8-3 07:28 PM 編輯
- using System.Data;
- using System.Data.SqlClient;
- namespace dbConection
- {
- public class dbConectionSample
- {
- public DataTable GetDataFromDataDase(string connectString)
- {
- DataSet ds = new DataSet();
- using (SqlConnection sqlCon = new SqlConnection(connectString))
- {
- string queryText = "";//查詢語法
- using (SqlCommand cmd = new SqlCommand(queryText,sqlCon))
- {
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.AddWithValue("參數", "值");
- using(SqlDataAdapter da = new SqlDataAdapter(cmd))
- {
- try
- {
- da.Fill(ds);
- }
- catch(Exception ex)
- {
- throw new Exception(ex.Message);
- }
- return ds.Tables[0];
- }
- }
- }
- }
- }
- }
複製代碼 這樣寫會幫你自動關閉
也會自動開啟資料庫...
|
|