-8

我已经使用数据连接服务器资源管理器连接到我的数据库,并且它也被添加到我的 web.config 中。现在有人可以告诉我如何查询吗?

4

1 回答 1

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
        }
    }
}
于 2013-07-05T15:15:18.653 回答