要从VB.net中的数据集中按日期选择记录 [英] Want to select the record by Date from Dataset in VB.net
问题描述
大家好,
我有一个数据集,该数据集的一列create_date的值为(5/12/2011 12.54.00),但是我想从数据集中选择该日期的值,而不是按时间(即2011年5月12日),
当前代码:
oDatatable.Select("create_date ="& cDate(Now.date))
但是它只会在数据和时间都相同的情况下选择行,但是我想选择数据是否相同.
请为此提供解决方案,
谢谢,
Dhiraj
Hi all,
I have a dataset, which have a column create_date which have value(5/12/2011 12.54.00) , but i want to select the value from dataset with date only not by time (i.e. 5/12/2011),
Current code:
oDatatable.Select("create_date = " & cDate(Now.date))
But it will only selecting row if the data and time both are same, but i want to select if the data is same.
Please give a solution for this,
Thanks,
Dhiraj
推荐答案
hi ,,
如此简单,仅在从veiwstate获取日期后才从数据库获取日期Now.date将在其后附加12:00:00 AM
因此在选择create_date时在您的选择查询中使用它.
,
so simple get date only from database once you get your date to veiwstate Now.date will append 12:00:00 AM with it
so use this in your select query while selecting create_date.
select CONVERT(VARCHAR(10), getdate(), 101) as create_date
您可以在数据集上使用LINQ作为
you can use LINQ on dataset for this as
//dt is the datatable where your data is
var qry=from row in dt.AsEnumerable()
where row.Field<datetime>("Create_date").ToShortDateString()==DateTime.Now.ToShortDateString()
select row;
DataTable dtFiltered=qry.CopyToDataTable();
</datetime>
我尚未在VB.Net上工作,所以我正在为C#.Net提供代码,希望您可以将其转换.
--Pankaj
I have not work on VB.Net so i am giving code for C#.Net hope you can convert it.
--Pankaj
这篇关于要从VB.net中的数据集中按日期选择记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!