您的位置:首页 > 数据库

C# 注册并使用sqlite 自定义函数

2014-03-08 14:43 337 查看
 C# 注册并使用sqlite 自定义函数
http://blog.csdn.net/keenweiwei/article/details/8899719 http://stackoverflow.com/questions/1943704/sqlitefunction-simple-not-working
public class Program
{
static void Main( string[ args )
{
test();
}

public static void test()
{
SQLiteConnection sqlConn = new SQLiteConnection( "Data Source=TestFoods.db;" );
sqlConn.Open();
SQLiteCommand sqlCmd = new SQLiteCommand( "PRAGMA integrity_check" , sqlConn);
sqlCmd.ExecuteNonQuery();
SQLiteFunction.RegisterFunction( typeof(DEMOIT) );
sqlCmd = new SQLiteCommand( "SELECT * FROM Foods Where Foods.Name DEMOIT '$butter' " , sqlConn );
sqlCmd.CommandType = CommandType.Text;
SQLiteDataAdapter liteAdapter = new SQLiteDataAdapter( sqlCmd );
DataSet dataSet = new DataSet();
liteAdapter.Fill( dataSet , "Foods" );
}

}

[SQLiteFunction( Name = "DEMOIT" , Arguments = 1 , FuncType = FunctionType.Scalar )]
public class DEMOIT : SQLiteFunction
{
public override object Invoke( object[] args )
{
return Convert.ToString( args[0] ) ;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息