且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查字符串是否包含c#中的特定日期

更新时间:2023-11-28 23:25:28

首先,在将日期发送到字符串之前停止将日期转换为字符串访问:事实上,完全停止做这样的事情!不要连接字符串以构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。请改用参数化查询,并将日期作为DateTime值传递,而不是字符串。这样系统之间就没有本地化问题...



然后,只需将测试从一返回到非零的行数更改为根据您要添加的续订日期检查您检索到的值。
First off, stop converting dates to strings before sending them to Access: in fact, stop doing things like that at all! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead, and pass your date as a DateTime value, not a string. That way there are no localisation problems between systems...

Then, just change your test for number of rows returned from "one" to "non-zero" and check the values you have retrieved against the renewal date you are about to add.