System.Data.SQLite和整理nocase与Vb.net?

时间:2017-03-12 08:08:31

标签: c# sql .net vb.net sqlite

我有一个简单的select语句,它在DB Browser for SQLite(82行)中有预期的结果。 相同的语句使用System.Data.SQLite(164行)在VB.NET中返回错误

声明是: SELECT * FROM [tblDictionary] INNER JOIN [tblLanguage] ON [tblDictionary]。[idLanguage] = [tblLanguage]。[idLanguage] WHERE [tblLanguage]。[LanguageName] like'Italian'

在VB.NET中使用SQLiteDataReader,行包含LanguageName Italian和Indonesian

我尝试过跟随WHERE子句,遇到同样的问题

WHERE UPPER([tblLanguage].[LanguageName]) = UPPER('Italian')
WHERE [tblLanguage].[LanguageName] = 'Italian'

要复制问题:

CREATE TABLE `tblLanguage` (
    `idLanguage`    integer NOT NULL PRIMARY KEY AUTOINCREMENT,
    `LanguageName`  varchar(30) NOT NULL
);
CREATE TABLE `tblDictionary` (
    `idDictionary`  INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    `idLanguage`    integer NOT NULL,
    `KeyValue`  nvarchar(300) NOT NULL,
    `DataValue` nvarchar(2000) NOT NULL,
    FOREIGN KEY(`idLanguage`) REFERENCES `tblLanguage`(`idLanguage`)
);
INSERT INTO tblLanguage (LanguageName) VALUES ('Indonesian');
INSERT INTO tblLanguage (LanguageName) VALUES ('Italian');
INSERT INTO tblDictionary (idLanguage, KeyValue, DataValue) VALUES (1, 'Delete', 'Hapus');
INSERT INTO tblDictionary (idLanguage, KeyValue, DataValue) VALUES (1, 'Edit', 'Edit');
INSERT INTO tblDictionary (idLanguage, KeyValue, DataValue) VALUES (2, 'Delete', 'Cancella');
INSERT INTO tblDictionary (idLanguage, KeyValue, DataValue) VALUES (2, 'Edit', 'Modifica');

VB代码:

Public Function SelectByLanguage(ByVal strLanguage As String) As DataTable
    Dim connection As SQLiteConnection = New SQLiteConnection("Data Source=H:\test.db;")
    Dim selectStatement As String _
        = "SELECT " _
        & "     [tblDictionary].[idDictionary] " _
        & "    ,[tblLanguage].[LanguageName] " _
        & "    ,[tblDictionary].[KeyValue] " _
        & "    ,[tblDictionary].[DataValue] " _
        & "FROM " _
        & "     [tblDictionary] " _
        & "INNER JOIN [tblLanguage] ON [tblDictionary].[idLanguage] = [tblLanguage].[idLanguage] " _
        & "WHERE [tblLanguage].[LanguageName] like 'Italian'"
    Dim selectCommand As New SQLiteCommand(selectStatement, connection)
    selectCommand.CommandType = CommandType.Text
Dim dt As New DataTable
    Try
        connection.Open()
        Dim reader As SQLiteDataReader = selectCommand.ExecuteReader()
        If reader.HasRows Then
            dt.Load(reader)
        End If
        reader.Close()
    Catch ex As SQLiteException
        MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
    Finally
        connection.Close()
    End Try
    Return dt
End Function

0 个答案:

没有答案