2013-07-05 151 views
-7

我已經連接到我的數據庫使用數據連接服務器資源管理器,同樣也添加到我的web.config。現在有人能告訴我如何查詢它嗎?SQL Server和Visual Studio 2012

+0

重複的很多問題.... http://stackoverflow.com/questions/9966301/sql-query-form-c-sharp, http://stackoverflow.com/questions/783294/executing-an-sql-statement-in-c,http://stackoverflow.com/questions/1504895/simple-sql-select-in-c –

回答

2

當然,你可以這樣做:在這個網站

using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["key_of_element"])) 
{ 
    c.Open(); 
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM Table")) 
    { 
     var reader = cmd.ExecuteReader(); 
     while (reader.Read()) 
     { 
      // do something with the data 
     } 
    } 
} 
相關問題