[英]Error: Missing operand after 'ItemRecord' operator
I want to show filtered values in dataGridView for specific date. 我想在dataGridView中显示特定日期的过滤值。 I have tried many options but none of them worked.
我尝试了很多选择,但没有一个起作用。 I want to show record in datagridview for specific date.
我想在datagridview中显示特定日期的记录。 Please suggest me some solution.
请给我一些解决方案。
string plus = dateTimePicker1.Value.AddDays(1).ToString();
string date = dateTimePicker1.Value.ToString();
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand("SELECT * FROM ItemRecord", con);
var dataset = new DataSet();
adapter.Fill(dataset);
this.itemRecordBindingSource.Filter = string.Format("SELECT * FROM ItemRecord WHERE cast(date as date) between '" + date +"' and '"+ plus +"'");
To form a filter value, specify the name of a column followed by an operator and a value to filter on.
要形成过滤器值,请指定列名,后跟运算符和要过滤的值。
So .Filter = "columnname = 'something'";
所以
.Filter = "columnname = 'something'";
is valid, the SELECT
is not. 有效,但
SELECT
无效。
CAST()
is also not valid as a filter does not re-query the database with SQL, for expressions you can use see this . CAST()
也无效,因为过滤器不会使用SQL重新查询数据库,有关表达式,您可以使用this 。 (You would use CONVERT()
) (您将使用
CONVERT()
)
To use what you have consider adding the WHERE
clause to the initial query instead. 要使用您所拥有的内容,请考虑将
WHERE
子句添加到初始查询中。
您可以在从数据库中选择时应用条件来解决此问题,或者应该像这样更改代码
this.itemRecordBindingSource.Filter = string.Format("date >= '{0:yyyy-MM-dd}' AND date < '{1:yyyy-MM-dd}'", date, plus);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.