【问题标题】:how to search the dataset for specific data如何在数据集中搜索特定数据
【发布时间】:2013-04-28 07:02:03
【问题描述】:

我只是想问如何在数据集中搜索特定数据,因为我想搜索特定关键字的摘要并将其绑定到转发器我有 where 表达式但它不起作用

        string keyword = "where summary like %"+ txtbKeyword.Text +"%" ;


        DataSet ds = new DataSet();
        int selectedTopicID = Convert.ToInt32(ddlTopics.SelectedValue);
        int selectedSkillID = Convert.ToInt32(ddlSkills.SelectedValue);
        int selectedTypeID = Convert.ToInt32(ddlTypes.SelectedValue);
        ds = Resoursce.Search_Resource(selectedTopicID, selectedSkillID, selectedTypeID);
        lbl_totalResult.Text = ds.Tables[0].Rows.Count.ToString();
        rp_resList.DataSource = ds.Tables[0].Select(keyword);
        rp_resList.DataBind();

System.Data.SyntaxErrorException 未被用户代码处理

 HResult=-2146232032
  Message=Syntax error: Missing operand after 'summary' operator.
  Source=System.Data
  StackTrace:
       at System.Data.ExpressionParser.Parse()
       at System.Data.DataExpression..ctor(DataTable table, String expression, Type type)
       at System.Data.DataTable.Select(String filterExpression)
       at Christoc.Modules.ResourcesFilter.View.ddlTopics_SelectedIndexChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\ideaPark\DesktopModules\ResourcesFilter\View.ascx.cs:line 120
       at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
       at System.Web.UI.Page.RaiseChangedEvents()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

【问题讨论】:

  • 请解释一下“搜索”是什么意思。您需要从数据集中的表中提取的数据子集吗?如果是,您的情况是什么(即。WHERE?)
  • 我正在寻找的是找到喜欢的记录

标签: c# asp.net dataset


【解决方案1】:

您可以使用 DataTable.Select() 方法。 http://msdn.microsoft.com/en-us/library/t5ce3dyt.aspx

微软的例子:

  // Presuming the DataTable has a column named Date. 
  string expression = "Date = '1/31/1979' or OrderID = 2";
  // string expression = "OrderQuantity = 2 and OrderID = 2";

  // Sort descending by column named CompanyName. 
  string sortOrder = "CompanyName ASC";
  DataRow[] foundRows;

  // Use the Select method to find all rows matching the filter.
  foundRows = table.Select(expression, sortOrder);

【讨论】:

    猜你喜欢
    • 2019-08-25
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 2017-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多