vb.net中的帮助日期格式

时间:2010-06-02 11:32:34

标签: vb.net

     Dim Con As OleDb.OleDbConnection
    Dim Sql As String = Nothing
    Dim Reader As OleDb.OleDbDataReader
    Dim ComboRow As Integer = -1
    Dim Columns As Integer = 0
    Dim Category As String = Nothing
    Dim oDatumMin As Date
    Dim column As String
    column = Replace(TxtDateMax.Text, "'", "''")
    'oDatumMin = Convert.ToDateTime(TxtDateMin.Text)

    oDatumMin = DtpMin.Value
    Dim oPath As String
    oPath = Application.StartupPath

    ' Select records.
    Con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & oPath & "\trb.accdb;")
    Dim cmd As New OleDb.OleDbCommand
    'Dim data_reader As OleDbDataReader = cmd.ExecuteReader()
    Sql = ("SELECT * FROM " & cmbvalue & " WHERE Datum>='" & oDatumMin & "'")
    cmd = New OleDb.OleDbCommand(Sql, Con)
    Con.Open()
    Reader = cmd.ExecuteReader()
    Do While Reader.Read()
        Dim new_item As New ListViewItem(Reader.Item("Datum").ToString)
        new_item.SubItems.Add(Reader.Item("Steleks i krpe za cišcenje-toal papir-ubrusi-domestos").ToString)
        new_item.SubItems.Add(Reader.Item("TEKUCINA ZA CIŠCENJE PLOCICA").ToString)
        new_item.SubItems.Add(Reader.Item("KESE ZA SMECE").ToString)
        new_item.SubItems.Add(Reader.Item("OSTALO-džoger-spužva za laminat").ToString)
        new_item.SubItems.Add(Reader.Item("PAPIR").ToString)
        LvIzvjestaj.Items.Add(new_item)

    Loop

    ' Close the connection.strong text
    Con.Close()``

当我从组合框中选择表格(cmbvalue)时 当我从日期时间选择器(dtp)中选择日期或者在最后一种情况下从texbox转换为日期和时间sql看起来像这样“SELECT * FROM Uprava WHERE Datum> ='2.6.2010 10:28:14'” 并且所有查询看起来都不错但是正在考虑

条件表达式中的数据类型不匹配。执行时的日期错误(oDatumMin) 访问中的列也设置为日期 我不知道还有什么可以尝试

2 个答案:

答案 0 :(得分:2)

我怀疑这是一个本地化问题。尝试将日期格式更改为应该被普遍认可的格式:

SELECT * FROM Uprava WHERE Datum >='2010/06/02 10:28:14'

[您的服务器区域设置/代码页是什么?]

答案 1 :(得分:1)

Dim sql As String = "SELECT * FROM MyTable WHERE Datum >= ?"
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql)
cmd.Parameters.Add(New OleDb.OleDbParameter("@Datum", OleDb.OleDbType.Date))
cmd.Parameters("Datum").Value = oDatumMin

http://msdn.microsoft.com/de-de/library/bbw6zyha.aspx