2011-09-02 26 views

回答

0

在我看來,放棄使用DataAdapter的想法是完全沒有必要的。這樣做是爲了讓數據表來代替:

using(SqlConnection con = new SqlConnection("Conectionstring")) 
{ 
    con.Open(); 
    using (SqlCommand commnand= new SqlCommand("StoredProcName",con)) 
    { 
      command.CommandType=CommandType.StoredProcedure; 
      SqlDataReader reader = command.ExecuteReader(); 
      DataTable table = new DataTable(); 
      table.Load(reader); 
      return table; 
    } 
} 

現在沒關係列你從PROC返回#,數據表將包含所有的人。

編輯:將以下部分添加到您的Web.config文件<configuration>部分下面替換您的實際connectionString。您應該能夠從您的設置文件中複製此內容。

,並立即建立的SqlConnection如下:

SqlConnection con 
= new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) 

注意 「的ConnectionString」 是在web.config中的連接字符串的name屬性。

另請參閱example here,萬一不是很清楚。

+0

這個決定對我很好,謝謝。但是現在我有連接問題。打開()。我從Properties.Settings.Default.myConnectionString使用connectionString,當我嘗試打開連接時,我得到錯誤:26形式的SQL服務器=(不知道如何解決這個問題。使用該連接字符串的TableAdapters工作正常... – Mitya

+0

@Mitya:see my編輯,我希望這很有幫助。 – Icarus