本文介绍了设置数据视图(或DataTable.DefaultView)RowFilter,它的自定义类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我开发的datagridview的过滤应用程序。我使用的数据视图的过滤数据的RowFilter属性。我的数据库表中包含INT和放大器; VARCHAR数据类型的字段。我想用在的RowFilter属性LIKE查询过滤数据视图,但喜欢只为字符串数据类型,而不是用于int数据类型。所以我想在 INT 数据类型字段转换为 VARCHAR 的数据类型,但我不想改变我的表结构体。我只想数据类型来更改临时对我的过滤条件而已。

任何人可以帮助我解决这个问题呢?

 字符串colname需要=产品;
字符串条件=111;
数据视图DV =新的数据视图();
dv.Table = ds.Tables [0];
dv.RowFilter =CAST(+ colname需要+以文本)LIKE'+状态+%';
 

解决方案

该RowFilter,它正在开展的.NET,不是SQL Server。它支持一组该框架文档中描述EX pressions有限。

<一个href="http://msdn.microsoft.com/en-us/library/system.data.datacolumn.ex$p$pssion.aspx">http://msdn.microsoft.com/en-us/library/system.data.datacolumn.ex$p$pssion.aspx

您应该能够喜欢使用以及转换,但不同于SQL服务器,它想要一个.NET类型。

  dv.RowFilter =CONVERT(+ colname需要+,S​​ystem.String)LIKE'+状态+%';
 

I'm developing an application on the datagridview filtering. I'm using RowFilter property of the dataview for the filtering data. My database table contains int & varchar data type fields. And I want to use "LIKE" query in the RowFilter Property for filtering the dataview but the "LIKE" is used only for the string data type and not for int data type. So I want to convert the int datatype field to the varchar datatype, but I don't want to alter my table structure. I just want the datatype to be changed temporary for my filtering condition only.

Can anybody help me in resolving this problem?

string colname="ProductID";
string condition="111";
DataView dv = new DataView();
dv.Table = ds.Tables[0] ;
dv.RowFilter ="CAST ("+colname+" AS TEXT) LIKE '"+ condition+"%'"  ;
解决方案

The RowFilter is being carried out by .NET, not SQL Server. It supports a limited set of expressions which are described in the Framework documentation.

http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

You should be able to use LIKE as well as CONVERT, but unlike SQL server, it wants a .NET type.

dv.RowFilter ="CONVERT("+colname+", System.String) LIKE '"+ condition+"%'"  ;

这篇关于设置数据视图(或DataTable.DefaultView)RowFilter,它的自定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:02