简体   繁体   English

如何在C#Windows Form应用程序中获取SQL Server中今天插入的数据的记录

[英]How to get record of today's inserted data in SQL Server in C# windows form application

I am developing an app in VS2010 c# to fetch a single row data from SQLServer and insert it to MySQL. 我正在VS2010 c#中开发一个应用程序,以从SQLServer获取单行数据并将其插入MySQL。

In this I have to check that how many records inserted today with one SQL Server query in SQL Server table name RAW_S001T01. 在此,我必须检查在SQL Server表名称RAW_S001T01中今天通过一个SQL Server查询插入了多少条记录。

I have tried to Google it but not getting exact answer. 我曾尝试使用Google进行搜索,但未获得确切答案。 I tried below query 我在下面查询

SELECT        Date_Time
FROM            RAW_S001T01
WHERE        (Date_Time = { fn CURDATE() })
ORDER BY Date_Time DESC

but not getting correct output. 但没有得到正确的输出。

Please help me with correct query. 请帮助我正确的查询。

Thanks in advance. 提前致谢。

If you only want records in RAW_S001T01 where Date_Time column is equals to the today date, you can modify your WHERE clause like this : 如果你只是想在记录RAW_S001T01其中Date_Time列等于今天日期,你可以修改你的WHERE这样的条款:

SELECT        Date_Time
FROM          RAW_S001T01
WHERE         Date_Time = CONVERT(date, getdate())
ORDER BY      Date_Time DESC

GETDATE() is an SQLServer function which will return the today date, like 2013-11-20 14:05:54.943 . GETDATE()是一个SQLServer函数,它将返回今天的日期,例如2013-11-20 14:05:54.943 Cast it in DATE to only keep the date part, ie 2013-11-20 . DATE强制转换,只保留日期部分,即2013-11-20

If I've understood your question, you only need to count the number of records added today by the Date_time column. 如果我理解了您的问题,则只需要计算Date_time列今天添加的记录数。 Hope I'm not mistaken. 希望我没有记错。
Try this; 尝试这个;

SELECT        Count(Date_Time) as No_Of_records_today
FROM          RAW_S001T01
WHERE        (Date_Time = getdate()) 

Thanks for your suggestions got correct answer ie 谢谢你的建议得到正确的答案,即

SELECT Date_Time FROM RAW_S001T01
WHERE  Date_Time >= CONVERT(DateTime, DATEDIFF(DAY, 0, GETDATE()))
ORDER BY Date_Time DESC

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Windows Service(C#)中的多线程在SQL Server 2008 R2中插入和更新同一插入的多条记录? - How to insert & update the same inserted multiple record in SQL Server 2008 R2 using multithread in windows service(C#)? C# Windows Form Application With SQL 服务器数据库部署 - C# Windows Form Application With SQL Server database deployment 将C#Windows窗体应用程序连接到Sql Server - Connecting C# Windows Form Application to Sql Server 如何部署使用sql server express 2012和crystal report开发的C#windows表单应用程序 - how to deploye C# windows form application developed with sql server express 2012 and crystal report 如何使用C#在Windows窗体应用程序中的SQL Server Compact数据库中搜索? - How to Search in SQL Server Compact Database in windows form application using C#? 如何配置SQL数据库C#Windows窗体应用程序 - How to configure sql database c# windows form application 带有Windows窗体应用程序的C#套接字服务器 - C# socket server with windows form application 如何授予SQL Server 2008数据库从C#Windows应用程序中的客户端系统插入数据的权限? - How to give the permissions to sql server 2008 database to insert the data from client system in c# windows application? C#Windows窗体如何将Datagridview到数据库(SQL Server)? - C# Windows Form How to Datagridview to Database (Sql Server)? 使用SQL Server和C#的多用户记录更新Windows应用程序 - Multi User record update Windows application using SQL Server & C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM