解决windows phone中使用sqlite时报SQLiteClient.SQLiteException: unrecognized token错误
来源:互联网 发布:澳大利亚移民知乎 编辑:程序博客网 时间:2024/05/21 10:48
将要插入sqlite数据库的汉字转换成Chart后+3变成其它汉字后再插入(试了一下效果还可以),这个方法只是应急的。觉得把它转化成sqlite能识别的数据类型才是正道,留给以后再尝试吧。
Windows Phone简单操作sqlite数据库,引用省略,编码如下
using SQLiteClient;using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Client{ public class VersionInfo { public VersionInfo() { } public VersionInfo(int Id, string Version,int ISUpdate) { id = Id; version = Version; IsUpdate = ISUpdate; } int _id; string _version; //是否升级(1:不升级,0:升级) private int isUpgrade; public int id { get { return _id; } set { _id = value; } } public string version { get { return _version; } set { _version = value; } } public int IsUpdate { get { return isUpgrade; } set { isUpgrade = value; } } } public static class SQLiteHelper { private static SQLiteConnection db = null; private static string fileName = "DB"; public static void openDB() { if (db == null) { db = new SQLiteConnection(fileName); db.Open(); } } public static void closeDB() { if (db != null) { db.Dispose(); db = null; } } public static bool isExistTable(string tablename) { bool flag = false; if (db != null) { try { SQLiteCommand cmd = db.CreateCommand("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='" + tablename + "'"); object obj = cmd.ExecuteScalar(); string msg = string.Empty; int iRet = Convert.ToInt32(obj); if (iRet > 0) { flag = true; } return flag; } catch (SQLiteException ex) { return flag; } } else { return flag; } } #region version public static void CreateVersionTable() { if (db != null) { try { if (!isExistTable("VersionTable")) { SQLiteCommand cmd = db.CreateCommand("Create table VersionTable(id INTEGER primary key,version text,IsUpdate INTEGER)"); int i = cmd.ExecuteNonQuery(); } } catch (SQLiteException ex) { } } } public static VersionInfo seleceVersion() { if (db != null) { try { SQLiteCommand cmd = db.CreateCommand("SELECT id,version,IsUpdate FROM VersionTable "); var lst = cmd.ExecuteQuery<VersionInfo>(); if (lst.Count() == 0) { return null; } else { VersionInfo tt = lst.ToList()[0]; if (!string.IsNullOrEmpty(tt.version)) { tt.version = StringDecoding(tt.version); } else { tt.version = ""; } return tt; } } catch (SQLiteException ex) { return null; } } else { return null; } } public static void insertVersionData(VersionInfo info) { if (db != null) { try { deleteVersionData();//先删除后添加 SQLiteCommand cmd = db.CreateCommand(""); cmd.CommandText = " Insert into VersionTable (version,IsUpdate) values ('" + (!string.IsNullOrEmpty(info.version) ? StringEncoding(info.version) : "") + "','" + info.IsUpdate + "')"; int rec = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { } } } public static void UpdateVersionData(VersionInfo info) { if (db != null) { try { SQLiteCommand cmd = db.CreateCommand(""); cmd.CommandText = "update VersionTable set version='" + (!string.IsNullOrEmpty(info.version) ? StringEncoding(info.version) : "") + "',IsUpdate='" + info.IsUpdate + "'"; int rec = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { string exmessage = ex.ToString(); } } } public static void deleteVersionData() { if (db != null) { try { SQLiteCommand cmd = db.CreateCommand(""); cmd.CommandText = " delete from VersionTable "; int rec = cmd.ExecuteNonQuery(); } catch (SQLiteException ex) { } } } #endregion //加密,把 string 转换成 char 后用自己的方法加密解密。这样解决了汉字插入数据库时报错SQLiteClient.SQLiteException: unrecognized token: "'发言" at SQLiteClient.SQ public static string StringEncoding(string pwd) { char[] arrChar = pwd.ToCharArray(); string strChar = ""; for (int i = 0; i < arrChar.Length; i++) { arrChar[i] = Convert.ToChar(arrChar[i] + 3); strChar = strChar + arrChar[i].ToString(); } return strChar; } //解密 public static string StringDecoding(string pwd) { char[] arrChar = pwd.ToCharArray(); string strChar = ""; for (int i = 0; i < arrChar.Length; i++) { arrChar[i] = Convert.ToChar(arrChar[i] - 3); strChar = strChar + arrChar[i].ToString(); } return strChar; } }}
在项目中调用方法即可:
SQLiteHelper.openDB(); SQLiteHelper.CreateVersionTable(); VersionInfo infoVersion = SQLiteHelper.seleceVersion(); SQLiteHelper.closeDB();
0 0
- 解决windows phone中使用sqlite时报SQLiteClient.SQLiteException: unrecognized token错误
- SQLiteException: unrecognized token:
- sqlite数据库存入的时候出现 unrecognized token: ""错误
- sqlite 出现 unrecognized token: "xxxx"
- greenDao使用中android.database.sqlite.SQLiteException: no such table
- windows phone:使用sqlite-net
- Android Studio中使用SQLite问题:android.database.sqlite.SQLiteException: no such table: XXX (code 1)
- Sqlite数据库中"未处理SQLiteException"问题
- android- 数据库 模糊搜索, 单引号 ’ 报错问题(SQLiteException: unrecognized token: “‘)
- Tomcat启动"Unrecognized Windows Sockets error: 0: JVM_Bind"错误解决
- Android SQLite 错误 SQLiteException: near "group": syntax error
- 关于“SqliteException: SQLite error no such column: ”错误
- windows phone中解决html乱码问题
- Unrecognized attribute 'targetFramework'.错误解决
- 如何在Windows Phone 8.1中引用SQLite数据库
- 使用Babel独立版编译ES6代码时报错误:Unexpected token <
- 用.net4.0中使用sqlite开发时报错,解决办法。
- Windows Phone中Silverlight Toolkit的使用
- bat 命令学习
- ubuntu 10 安装samba服务,windows下磁盘驱动映射
- Linux kernel测试初探
- 基于Weblogic11的Mule3.5部署指南
- about unicode
- 解决windows phone中使用sqlite时报SQLiteClient.SQLiteException: unrecognized token错误
- DBCC大全集之(适用版本MS SQLServer 2008 R2)----DBCC CLEANTABLE回收表或索引视图中已删除的可变长度列的空间
- [Ext.Net]动态生成控件(二)--js动态添加文本框
- 网页中显示xml,直接显示xml格式的文件
- Visual Studio 必备神器
- diff & patch 制作及打补丁
- 【玩转cocos2d-x之三十三】游戏嵌入Webview网页
- Django负载均衡session共享
- JQuery返回Json日期格式的問題 jquery对时间/Date(1387900800000)进行处理