2014-02-24 43 views
-1

我在asp.net上的餐廳網站上工作....我有兩個表在數據庫中。配方和審查......我一直在使用相同的代碼,除了表中提取從檢查表,並在那裏我連接數據庫連接Asp.net sql連接錯誤在兩頁

using con = 
    new SqlConnection(
      ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString 
    ); 
da = new SqlDataAdapter("select * from MCN", con); 
da.Fill(dt); 

現在在配方頁面我想獲取從配方表數據..即時通訊數據名稱..我有錯誤說con,da已經使用..更改名稱..bt仍然面臨問題...可能是我犯了一個概念錯誤,因爲即時通訊非常新的編碼。

+0

_What究竟該錯誤後說要關閉連接?_ – SLaks

+0

騙子已被使用。 – user3341165

回答

0

嘗試

// `using` scopes `con` variable and automatically disposes of it (closes) 
using(SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString)) { 
    con.Open(); // you must open the connection before using it 
    using (SqlDataAdapter da = new SqlDataAdapter("select * from MCN", con)) { 
    da.Fill(dt); 
    } // we also want to automatically clean up our SqlDataAdapter 
} // even on exception, connection is closed automatically here. nice, huh? 
0

您可能需要retrieveing數據

+0

退出該項目,然後重新開始!爲我工作 – user3341165