一聚教程网:一个值得你收藏的教程网站

热门教程

asp.net Access的数据库连接字符串总结

时间:2022-06-25 04:19:40 编辑:袖梨 来源:一聚教程网

asp教程.net access的数据库教程连接字符串总结

1.access的数据库连接字符串。在web.config文件中配置access文件。


string constring = configurationmanager.apps教程ettings["conn"]+httpcontext.current.server.mappath("~")+configurationmanager.appsettings["source"];

2.access数据库对关键字敏感,对于password这样的关键字,需要加括号进行查询,否则会报错。

string querystring="insert into users([username],[password],[gendor],[createtime]) values(@username,@password,@gendor,@createtime)";

3.对于日期类型的字段,需要先转换为字符串,再转化为日期。

oledbparameter par=new oledbparameter("@createtime",convert.todatetime(userinfo.createtime.tostring());

4.access数据库的参数有严格的顺序,如果参数的顺序不对的话,执行时不会报错,但是不会做插入或更新操作,对数据库不会产生任何影响。

string updatestring = "update users set [username]=@username,[password]=@password,[gendor]=@gendor where [id]=@id";
oledbparameter[] pars ={
                    new oledbparameter("@username",userinfo.username),
                    new oledbparameter("@password",userinfo.password),
                    new oledbparameter("@gendor",userinfo.gendor),
                    new oledbparameter("@id",userinfo.id)};//如果将id参数写在前面,执行不会成功

 

热门栏目