使用空单元格查询仅适用于" LEN(名称)> 1或LEN(名称)< 2"

时间:2016-03-02 08:46:09

标签: vb.net oledb ms-access-2000

在我的程序(vb.net)中,当我使用&#34; oleDBQuery&#34;时,我只能在某些单元格为空时启动LEN(EnterName) > 1 or LEN(EnterName) < 2来访问Acces 2000表。 ,这很奇怪,原因&gt; 1和&lt; 2将只选择任何单元格,就像没有LEN一样。

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

  

&#34;给定的转换无效&#34;

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

如果你能帮助我会很酷。

Picture of Database and vb Application (using 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

1 个答案:

答案 0 :(得分:0)

使用IsDbNull()

似乎需要正确处理NULL值

请参阅vb.net - read null value from database