您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Access数据库创建、使用

2026/1/28 13:20:48发布14次查看
1、创建access数据库表 1)在office中打开microsoft access2010,选择空数据库创建数据库studentinfo。 2)创建新表,在表格第一列选择数据类型,并输入列名。 3)点击保存,输入数据库表名student,完成创建。 4)将创建的数据库拷贝到项目的debug文件中即
1、创建access数据库表
1)在office中打开microsoft access2010,选择空数据库创建数据库studentinfo。
2)创建新表,在表格第一列选择数据类型,并输入列名。
3)点击保存,输入数据库表名student,完成创建。
4)将创建的数据库拷贝到项目的debug文件中即可使用。
2、连接、打开access数据库
1)数据库连接语句:public string connectionstring = provider=microsoft.ace.oledb.12.0;data source= studentinfo.accdb; 
2)常用的查询、执行sql语句:
public dataset query(string strsql) { using (oledbconnection conn = new oledbconnection(connectionstring)) { dataset ds = new dataset(); try { conn.open(); oledbdataadapter command = new oledbdataadapter(strsql, conn); command.fill(ds, ds); } catch (system.data.sqlclient.sqlexception ex) { throw; } return ds; } } public int executesql(string strsql) { using (oledbconnection conn = new oledbconnection(connectionstring)) { using (oledbcommand cmd = new oledbcommand(strsql, conn)) { try { conn.open(); int rows = cmd.executenonquery(); return rows; } catch (system.data.sqlclient.sqlexception e) { conn.close(); throw e; } } } } public object getsingle(string strsql) { using (oledbconnection conn = new oledbconnection(connectionstring)) { using (oledbcommand cmd = new oledbcommand(strsql, conn)) { try { conn.open(); object obj = cmd.executescalar(); if ((object.equals(obj, null)) || (object.equals(obj, system.dbnull.value))) { return null; } else { return obj; } } catch (system.data.sqlclient.sqlexception e) { conn.close(); throw e; } } } }
view code3)输入常用的数据库sql语句即可完成调用。
常见问题:
1)添加accessdatabaseengine数据接口驱动。
2)如何不能识别.accdb格式数据库,则查看:
http://wenku.baidu.com/link?url=qq3f2llz8gl9zkejhkae4l1bbeavcigo2wxer0mpvqxbpcqys5vgiczme2r1lpcsmd3beygnfi1lwrv4mlixhlaniwnzogstdkgtebnluum
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product