關于SQL轉換為ACCESS應該注意的問題

来源:互联网 发布:苏联发展数据大全 编辑:程序博客网 时间:2024/06/16 00:01

最近公司有個項目,需要把SQL版的轉換為ACCESS。。。其實在VS2005.NET中,如果設計的當初采用三層設計的話,轉換是很容易的。但是有幾個地方要注意,我是摸索得到的。中間費了不少周折。

1.sqlserver中 整數型的可以加 ' ' 但是access不行

     比如 int a=5;

在SQL中可以這么寫,select * from table where num='"+a+"' 或者 select * from table where num='5'

但是access中就不能加引號,必須是 select * from table where num=5

or    select * from table where num="+a+" 少2個單引號

2.sqlserver中 添加變量的參數時,只要指定了,就可以壓參,先后順序沒關系。但是ACCESS中必須按照先后順序,不然就會出錯。。

比如:

select * from table where num=@num and tag=@tag;

sqlparameter par1=new sqlparameter("@tag",str1);

sqlparameter par2=new sqlparameter("@num",str2);  //@num和@tag的次序的反的

但是在ACCESS中就必須一致。。

select * from table where num=@num and tag=@tag;

sqlparameter par1=new sqlparameter("@num",str2);  

sqlparameter par2=new sqlparameter("@tag",str1);

SQL中是支持參數名配對的。。。

3.日期語法不同
如:
sql server:
select * from tablename where postdate='"+ mydate +"'
Access:
select * from tablename where postdate='#+ mydate +#'

4.还有一点是特别,特别奇观的,就是日期型的一定要指定oledb.type 为date 不然不行哦