SqlCommand 对象-ExecuteReader() 方法的使用

作者:vkvi 来源:ITPOW(原创) 日期:2008-6-17
string connString = "Data Source=(local);Initial Catalog=Db;Integrated Security=SSPI;";
using (SqlConnection conn = new SqlConnection(connString))
{
    conn.Open();
    string sql = @"select top 1 * from tbl order by id desc";
    using (SqlCommand cmd = new SqlCommand(sql, conn))
    {
        using (SqlDataReader reader = cmd.ExecuteReader())
        {
            if (reader.Read())
            {
                _info.Text = reader["title"].ToString();
            }
            reader.Close();
        }
    }
    conn.Close();
}
相关文章