sqlite中替代变量的一种解决方法
public static DataTable GetAnPaiBySYSID(String ShiYanShiID) { DataTable rdt = new DataTable(); //建立数据库连接 SQLiteDBManager dba = new SQLiteDBManager(); try { string sSql = @"DELETE FROM VarTable; INSERT INTO VarTable ( name, value ) SELECT 'AheadTimePart' AS name, '-' || PeiZhiXiangZhi || ' minutes' FROM LM_JC_XiTongPeiZhiXiang WHERE PeiZhiXiangID = 'LM_PZS_0025'; INSERT INTO VarTable ( name, value ) SELECT 'DelayTimePart' AS name, '+' || PeiZhiXiangZhi || ' minutes' FROM LM_JC_XiTongPeiZhiXiang WHERE PeiZhiXiangID = 'LM_PZS_0025'; SELECT KaoQingAnPaiID, ShiYanShiID, MenName, KaiShiRiQi, JieShuRiQi, ShiFouMoRen, SystemType, SystemTypeInfo FROM LM_KQ_KaoQingAnPai WHERE ShiYanShiID = @ShiYanShiID AND datetime('now', '+8 hour') >= datetime(KaiShiRiQi, ( SELECT value FROM vartable WHERE name = 'AheadTimePart' limit 1 ) ) AND datetime('now', '+8 hour') <= datetime(JieShuRiQi, ( SELECT value FROM vartable WHERE name = 'DelayTimePart' limit 1 ) ) "; SQLiteParameter[] array = new SQLiteParameter[] { new SQLiteParameter("@ShiYanShiID", ShiYanShiID.ToUpper()) }; // 执行查询语句 rdt = dba.GetSqlDataTable(sSql, array); } catch (Exception ex) { //抛出异常 throw ex; } finally { dba.Dispose(); } return rdt; }