-1

在我的程序(vb.net)中,我只能oleDBQuery在有一些单元格为空时启动 a 来访问 Acces 2000 表,当我使用“ LEN(EnterName) > 1 or LEN(EnterName) < 2”时,这很奇怪,因为 > 1 和 <2 只会选择任何单元格,就像没有伦。

如果我不使用 LEN,那么我会收到此错误消息

“给定的转换无效”

这不是唯一的问题。当我使用 LEN 时,它不会返回我需要的空单元格。

如果你能帮助我会很酷。

数据库和 vb 应用程序的图片(使用 LEN) sry 我需要像素化除这一行之外的任何内容,这是数据保护的原因。如果您需要更多信息,请询问我!

代码:

    Using connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\temp\WE2015_NEU dura logo.mdb;Persist Security Info=False;")

        'fills the combobox with information from the database
        '═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
        connection.Open()                                                                                                                      '║
        Dim command_Name_Firmen As New OleDbCommand("SELECT Betrieb FROM MaterialHist Where LEN(Betrieb) > 1 or LEN(Betrieb) < 2", connection) '║
        Dim reader_Name_Firmen As OleDbDataReader = command_Name_Firmen.ExecuteReader()                                                        '║
        While reader_Name_Firmen.Read()                                                                                                        '║
            DatenbankboxDrölf.Items.Add(reader_Name_Firmen.GetString(0))   ''Here in the Brackets is the error if i would not use LEN          '║(Datenbankdrölf = Combobox)
        End While                                                                                                                              '║
        reader_Name_Firmen.Close()                                                                                                             '║
        connection.Close()                                                                                                                     '║
        '═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

    End Using
4

1 回答 1

0

看来您需要正确处理 NULL 值,使用IsDbNull()

请参阅vb.net - 从数据库中读取空值

于 2016-03-17T07:50:27.483 回答