数据读取器用于查找表中的值或不查找表中的值 [英] Data reader is used to find the values in the table or not

查看:112
本文介绍了数据读取器用于查找表中的值或不查找表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Datareader用于查找表中是否存在值...需要它的代码...

Hi,

Datareader is used to find the values is exsist or not in the table...need a code for it...

推荐答案

您可以使用dr.read()或Dr.HasRows

You can use dr.read() or dr.HasRows

SqlCommand myCMD = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" +
                                  "SELECT EmployeeID, LastName FROM Employees", nwindConn);
nwindConn.Open();

SqlDataReader myReader = myCMD.ExecuteReader();

do
{
  Console.WriteLine("\t{0}\t{1}", myReader.GetName(0), myReader.GetName(1));

  while (myReader.Read())
    Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));

} while (myReader.NextResult());

myReader.Close();
nwindConn.Close();


您可以使用 DataTable.Select [
You may use the DataTable.Select[^] method to achieve this behaviour.


这篇关于数据读取器用于查找表中的值或不查找表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆