2013-07-05 2 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 
     } 
    } 
}