如何使用后面的代码检查日期是否已经存在



我只有一个日期,只有一个" dateofyear",我想在插入文本框中的日期之前检查db中的日期,但在c#。

中使用代码。

我将举一个示例,例如我想做的,我知道不是正确的代码或我需要的,而是一个例子,因为我不希望人们过去或使用sqlcommand/sqlserver和其他解决方案我想要类似代码的东西。

DateTime InvoiceDateFrom = new DateTime();
DateTime InvoiceDateTo = new DateTime();
InvoiceDateFrom = Convert.ToDateTime(txtDatRiferiment.Text);
InvoiceDateTo = Convert.ToDateTime(txtDatRiferiment.Text);
if (InvoiceDateFrom == InvoiceDateTo)
{
    errorMessage = vea.ErrorMessage;
}

您可以使用datetime.compareto方法:

if(InvoiceDateFrom.CompareTo(InvoiceDateTo) == 0){
    errorMessage = vea.ErrorMessage;
}

更多信息。

相关内容

最新更新