1、最常规的用法 参考官方例子

            string sql = "";
            SqlCommand cmd = new SqlCommand(sql, this.sqlCn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable inv = new DataTable();
            inv.Load(dr);
            dr.Close();

2、上面的是单查询,当我们多查询的时候就有区别了,参考

if(dr.HasRows){
//此处判断 }

多查询最场景的场景是我要分页查询数据,每次都要带出总数(count),分两次查也行,不过我喜欢一次查询多表

table.Load(reader);
count = 0;
if (reader.Read())//此处是Load后的坑,不用在执行NextResult(),参考链接中的大哥也是这样
{
  count = Convert.ToInt32(reader[0]);
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-11-30
  • 2022-12-23
  • 2021-10-29
  • 2022-01-16
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案