首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Access数据库 :要查找处于两个字符串之间的值,如何写

2012-10-20 
Access数据库 :要查找处于两个字符串之间的值,怎么写?private void selectActivity(int index, string s1,

Access数据库 :要查找处于两个字符串之间的值,怎么写?
private void selectActivity(int index, string s1,string s2)
{

  string sql= "select * from acttable where where act_start>='" + s1 + "' and act_stop<='" + s2 + "'"; 

}
我要在数据库中查找大于s1 且小于s2之间的所有记录,但照上面sql语句执行 ,不对!求大神!!!!

[解决办法]
去掉单引号。
[解决办法]
是什么类型?如果日期的话试试看between
[解决办法]
string sql= "select * from acttable where where act_start>='" + s1 + "' and act_stop<='" + s2 + "'";

里面多了个where

string sql= "select * from acttable where act_start>='" + s1 + "' and act_stop<='" + s2 + "'";
另外还可以试试

string sql= "select * from acttable where act_start between #" + s1 + "# and #" + s2 + "#";

[解决办法]

SQL code
DECLARE @t table(    id int,    cDate datetime)insert into @t  select 1, GETDATE()  union  select 2, DATEADD("D",1,GETDATE())  union  select 3, DATEADD("D",2,GETDATE())  DECLARE @start datetime='2012-10-04'DECLARE @end datetime='2012-10-07'SELECT *FROM @tWHERE cDate between @start and @end--测试结果--1    2012-10-04 15:40:33.360--2    2012-10-05 15:40:33.360--3    2012-10-06 15:40:33.360 

热点排行