-1

I'm using VB.NET and VS 2008, and having a problem selecting dates.

In the appointmentsmain table are 2 fields, StartDate and CustomerName

The StartDate contains dates formatted in this way ..

2013-01-29 11:16:41

Dim strSQL As String = "select * from  AppointmentsMain"

Selecting all as above and reading via a DataReader throws the error. If I select the customername field only, it works fine.

I am using the System.Data.SQLite wrapper.

Below is the code. It breaks on the msgbox. Try

    Dim cn As SQLiteConnection

    Dim cmd As SQLiteCommand

    Dim rdr As SQLiteDataReader

    Dim strSQL As String = "select * from  AppointmentsMain"

    cn = New SQLiteConnection(strPublicConnectionString)

    cn.Open()

    cmd = New SQLiteCommand(strSQL, cn)

    rdr = cmd.ExecuteReader

    If rdr.Read Then

    MsgBox(rdr("startdate"))

    End If

    rdr.Close()

    cn.Close()

    Catch ex As Exception

    End Try 
4

3 回答 3

0

rdr("startdate") 返回什么?这是空的吗?不能解析成字符串吗?

于 2013-01-29T18:39:40.193 回答
0

正如 Matthew 所说,首先要检查的是rdr("startdate"). 您的问题将其称为,StartDate但您的代码将其称为startdate,因此可能与区分大小写有关。您可以尝试rdr("StartDate")改用。

于 2013-01-29T18:43:23.807 回答
-1

我也有这个问题。从我读过的内容来看,似乎不兼容的字符编码可能已应用于日期。我能够通过使用这样的东西来解决这个问题:

选择日期(开始日期)作为开始日期,... FROM AppointmentsMain

我知道这是一个老问题,但我无法在任何地方找到解决方案......

于 2013-09-27T21:18:36.977 回答