C# 注册并使用sqlite 自定义函数
2013-05-08 12:55
323 查看
1,sqlite 没有 ToUpper 的自带函数。 没关系,我们可以创建它;
2,sqlite 不能直接创建自定义函数,不能像 sql server中那样方便创建并使用。没关系,我们照样可以创建它,创建成功后,我们照样可以随心所欲(比如 批量更新等)。
效果:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%爱你中国')"); // Wa*%ANZG
方案:
step1: 创建类 ToUpper 和 GetChinesePYChar
step2:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%爱你中国')"); // Wa*%ANZG
step3:
public static string ResetAllPointNameChinesePYChar()
{
return "update tblLinePoint set ChinesePYChar=GetChinesePYChar(Name)";
}
结束。
参考 :
http://blog.csdn.net/huanshanv20008/article/details/7635092
2,sqlite 不能直接创建自定义函数,不能像 sql server中那样方便创建并使用。没关系,我们照样可以创建它,创建成功后,我们照样可以随心所欲(比如 批量更新等)。
效果:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%爱你中国')"); // Wa*%ANZG
方案:
step1: 创建类 ToUpper 和 GetChinesePYChar
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SQLite; namespace MetroGuide { [SQLiteFunction(Name = "ToUpper", Arguments = 1, FuncType = FunctionType.Scalar)] public class ToUpper : SQLiteFunction { public override object Invoke(object[] args) { return args[0].ToString().ToUpper(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SQLite; namespace MetroGuide { [SQLiteFunction(Name = "GetChinesePYChar", Arguments = 1, FuncType = FunctionType.Scalar)] public class GetChinesePYChar : SQLiteFunction { public override object Invoke(object[] args) { string sOrigion = args[0].ToString(); return Common.GetPYString(sOrigion); } } }
step2:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%爱你中国')"); // Wa*%ANZG
step3:
public static string ResetAllPointNameChinesePYChar()
{
return "update tblLinePoint set ChinesePYChar=GetChinesePYChar(Name)";
}
结束。
参考 :
http://blog.csdn.net/huanshanv20008/article/details/7635092
相关文章推荐
- C# 注册并使用sqlite 自定义函数
- SQLite使用总结(C#版 潘鹏)
- C# 使用 Dapper 实现 SQLite 增删改查
- C# 使用sqlite 轻量级数据库
- 如何高效使用SQLITE .NET (C#)
- C#使用VS2005制作水晶报表 提示注册 解决方法
- c#使用RSA进行注册码验证
- C# 下sqlite简单使用
- 如何使用Regasm.exe注册C#创建的类库
- [课堂实践与项目]手机QQ客户端--4期(SQLite的加入,注册,找回,登录界面的修改):建立关于QQ注册类,使用SQLite进行存储,
- c#使用SQLiteDataAdapter配合DataGridView增删改查数据
- 在.NET C#中使用sqlite
- C#三层架构的UserService类(注册登录使用)
- C# system.data.sqlite使用
- C# 使用Sqlite 如何返回统计行数
- c# 连接SQLite及SQLite使用小结
- C# 使用Mono.SQLite进行跨平台开发
- C#下SQLite的使用
- 在Windows 8 Metro应用中使用C# 连接SQLite
- 如何高效使用SQLite事务 .net (C#)