1

我正在 VB 中的 asp.net 中构建预约系统 Web 应用程序,

我只是想检查是否已在从日历控件中选择的日期进行了约会。我正在使用 Linq 进行绑定,但是当我需要 ddmmyyyy 时,日历中的格式是 mmddyyyy,我的约会输入 int sql 表,时间为 20/09/2012 10:00:00

尝试在 db.apps 中使用 p 中的 linq,其中 p.date=mycontrol.selecteddate

不产生结果

添加了一些代码:-

 Dim myDate As Date = appCalender.SelectedDate



        Dim stat = From a In db.Appointments
                 Where a.dateAndTime = DateTime.Parse(myDate).ToString("ddMMyyyy")
                 Select New With {a.dateAndTime}

        Dim myList As List(Of String) = Nothing
        For Each a In stat

            myList.Add(a.dateAndTime)

        Next

        ListBox1.DataSource = myList
        ListBox1.DataBind()

我不确定代码 DateTime.Parse,,,, 是否正确,我从日历中选择的所选日期有很多约会,但我认为 DateTime 格式没有正确转换为 SQL

SQL 中的约会数据类型是 datetime

4

1 回答 1

0

您没有比较相同的数据类型。

Where a.dateAndTime = DateTime.Parse(myDate).ToString("ddMMyyyy")

如果您的数据库(和 Linq)中的列是 DateTime,则“=”右侧的值是一个字符串。它不会匹配。试试这个?

Where a.dateAndTime = DateTime.Parse(myDate)

编辑

此外,看起来您只是从日历中获取日期,而不是时间:

Dim myDate As Date = appCalender.SelectedDate

但是您说您的日期存储为“20/09/2012 10:00:00”

20/09/2012 10:00:00 != 20/09/2012 00:00:00

这可能是正在发生的事情。

试试这个

Dim myDate As DateTime =  DateTime.Parse(appCalender.SelectedDate)

Dim stat = From a In db.Appointments
           Where a.dateAndTime >= myDate And a.dateAndTime < myDate.AddDays(1)
           Select New With {a.dateAndTime}
于 2012-04-19T14:11:31.307 回答