博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ado.net 学习 06 DataSet,DataTable提供一个有用的方法Select()
阅读量:4566 次
发布时间:2019-06-08

本文共 1481 字,大约阅读时间需要 4 分钟。

1.DataTable提供一个有用的方法Select(),它可以使用SQL表达式查询某行,Select()方法使用的表达式和select语句的Where子句的作用一样,其依据是DataTable中已经存在内在数据。

  DataRow[] matchRows = ds.Tables["Products"].Select("discontinued=1");

 

1     protected void Page_Load(object sender, EventArgs e) 2     { 3         // Create the Connection, DataAdapter, and DataSet. 4         string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString; 5         SqlConnection con = new SqlConnection(connectionString); 6  7         string sqlProd = "SELECT ProductName, CategoryID,discontinued FROM Products"; 8  9         SqlDataAdapter da = new SqlDataAdapter(sqlProd, con);10         DataSet ds = new DataSet();11 12         try13         {14             con.Open();15             // Fill the DataSet with the Products table.16             da.Fill(ds, "Products");17         }18         finally19         {20             con.Close();21         }22 23         StringBuilder htmlStr = new StringBuilder("");24 25         DataRow[] matchRows = ds.Tables["Products"].Select("discontinued=1");26 27         foreach (DataRow childRow in matchRows)28         {29             htmlStr.Append("
  • ");30 htmlStr.Append(childRow["ProductName"].ToString());31 htmlStr.Append("
  • ");32 }33 htmlStr.Append("");34 35 // Show the generated HTML code.36 HtmlContent.Text = htmlStr.ToString();37 }

    运行结果:

    对比

    转载于:https://www.cnblogs.com/hefu_cao/archive/2013/05/29/3107227.html

    你可能感兴趣的文章
    02_ListActive中响应事件 并LogCat输出
    查看>>
    doubleclick adx note
    查看>>
    Celery框架
    查看>>
    [c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
    查看>>
    [转载,感觉写的非常详细]DUBBO配置方式详解
    查看>>
    linux Valgrind使用说明-内存泄漏
    查看>>
    Android在Eclipse上的环境配置
    查看>>
    面向对象(五)
    查看>>
    android平台下使用点九PNG技术
    查看>>
    Python学习3,列表
    查看>>
    最长回文子串
    查看>>
    JAVA基础-JDBC(一)
    查看>>
    js中for和while运行速度比较
    查看>>
    简单理解什么是递归(阶乘演示)
    查看>>
    http协议
    查看>>
    js倒计时,页面刷新时,不会从头计时
    查看>>
    洛谷1156垃圾陷阱
    查看>>
    python ==》 递归
    查看>>
    简单网络请求封装
    查看>>
    django —— MVT模型
    查看>>