2015-04-01 51 views
0

我想將SQLite的編碼設置爲UTF-16。我怎麼能從代碼做到這一點? prefferably在vb.net,但我能夠到C#轉換爲vb.net在.net中設置sqlite編譯指令爲「UTF-16」

我使用數據庫輔助類從這個網址,我轉換成vb.net代碼: http://tech.just4sharing.com/Pages/ASP/How-to-use-SQLite-database-in-Visual-Studio.aspx

我想這VB .net代碼:

 dbConnection = "Data Source=database.s3db;PRAGMA encoding = ""UTF-16"";" 

但是這個diddent工作。
後@Dai後我在SQLiteDatabase輔助類的構造函數嘗試這樣做,刪除舊的數據庫

vb.net代碼:

dbConnection = "Data Source=database.s3db;" 
    Dim cnn As New SQLite.SQLiteConnection(dbConnection) 
    cnn.Open() 
    Using cmd As SQLiteCommand = cnn.CreateCommand() 
     cmd.CommandText = "PRAGMA encoding = ""UTF-16"";" 
     cmd.ExecuteNonQuery() 
    End Using 
    cnn.Close() 

C#代碼:

SQLiteConnection c = new SQLiteConnection(dbConnectioN) 
c.Open() 
using(SQLiteCommand cmd = c.CreateCommand()) { 
cmd.CommandText = "PRAGMA encoding = \"UTF-16\""; 
cmd.ExecuteNonQuery(); 
} 
c.Close() 

但這也做了工作,管理員(SQLite的IDE)仍然難過它是UTF-8

回答

0

SQLite PRAGMA語句被評估爲SQL命令,s o不是連接字符串的一部分。這是記錄在他們的網站:

https://www.sqlite.org/pragma.html

的PRAGMA語句是特定的SQL擴展SQLite和用於修改SQLite庫的操作或要查詢的內部(非表SQLite庫)數據。 雜注語句使用相同的接口,其他的SQLite命令(如SELECT,INSERT)發佈

(重點煤礦)

所以設置編碼:

using(SQLiteCommand cmd = c.CreateCommand()) { 
    cmd.CommandText = "PRAGMA encoding = \"UTF-16\""; 
    cmd.ExecuteNonQuery(); 
} 
+0

謝謝,我更新了這個問題,我希望你能看看它? – user2653652 2015-04-01 18:39:06