SQL Server和Visual Studio 2012

问题描述:

我已经连接到我的数据库使用数据连接服务器资源管理器,同样也添加到我的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 –

当然,你可以这样做:在这个网站

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 
     } 
    } 
}