As for databases, there are quit many kinds such as foxpro, mysql, sqlserver, etc.

But when we need to build a project which should be portable, the .mdb(Access) databases may be one of the best choices.

Here we go.:)

1.Creating a .mdb database

Actually this simple question really got me at the beginning.But it can be easy in another way.

Firstly, we should adduct the libraries —— 'Microsoft ActiveX Data Objects 2.8 Library' and 'Microsoft ADO Ext. 2.8 for DDL and Security'.

Then,put a 'using ADOX;'.

After that you can create a database like this:

 string filename=@"c:\1.mdb";
string phrase = "provider=Microsoft.Jet.OLEDB.4.0;data source=\"" + filename + "\"";
(new Catalog()).Create(phrase);

2.Querying a .mdb database

This is much easier than that in VB6 because almost every function has been supported by the .Net Framework.

Firstly, we need to connect to the database and then query it.

After All,WE NEED TO CLOSE IT!!!!!!

Like this:

 string filename = @"c:\1.mdb";
string pwd = "";
string phrase = "provider=Microsoft.Jet.OLEDB.4.0;data source=\"" + filename + "\"";
// add password if neccessary
if (pwd != null) phrase += "; Jet OLEDB:Database Password=" + (string)pwd;
OleDbConnection conn = new OleDbConnection(phrase);
conn.Open(); //very important, don't forget it string sql = "select * from database"; //sql sentence
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn); DataTable dt1 = new DataTable(); oda.Fill(dt1); //get table of data foreach (DataRow dr in dt1.Rows)
{
foreach (DataColumn dc in dt1.Columns) //print every rows
{
console.Write((string)dr[dc]+" "); //print every columns
}
console.Writeln();
} conn.close();

3.Modifying a .mdb database

It can be quit similiar to the Quering Process.The main difference is the class we use is \( OleDbCommand \) now.

Coding like this:

 string filename = @"c:\1.mdb";
string pwd = "";
string phrase = "provider=Microsoft.Jet.OLEDB.4.0;data source=\"" + filename + "\"";
// add password if neccessary
if (pwd != null) phrase += "; Jet OLEDB:Database Password=" + (string)pwd;
OleDbConnection conn = new OleDbConnection(phrase);
conn.Open(); //very important, don't forget it string sql = "update database set abc='123' where bcd='234'"; //sql sentence
OleDbCommand comm = new OleDbCommand(sql, conn);
comm.ExecuteNonQuery(); //the feedback value is the number of rows it actually processed. conn.close();

【C#】Creating/Querying/Modifying the .mdb databases的更多相关文章

  1. 【Error】Creating Server TCP listening socket *:6379: bind: No such file or directory

    redis 运行服务时报错: Creating Server TCP listening socket *:6379: bind: No such file or directory 解决方法,依次输 ...

  2. 【c#】ADO操作Access的mdb数据库只能读不能修改的解决方法

    在使用ACCESS数据库时连接字符串如 string strcon=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Access操作\简易 ...

  3. 【贪心/DP/单调队列】【CF1029B】Creating the Contest

    Description 给你一个单调不下降的长度为n的序列,请你找出一个最长的子序列,满足找出的子序列中,\(A_i<=A_{i-1}~\times~2\),其中i为下标,A为找出的子序列.对于 ...

  4. 【CF1029B】Creating the Contest(贪心)

    题意: n<=2e5 思路:可以证明答案一定是极长的一段中取最大值 #include<cstdio> #include<cstring> #include<stri ...

  5. 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;

    一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...

  6. 【CodeChef】Querying on a Grid(分治,最短路)

    [CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最 ...

  7. 【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE

    [12c]扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE 在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的 ...

  8. 【Java】-NO.20.Exam.1.Java.1.001- 【1z0-807】- OCEA

    1.0.0 Summary Tittle:[Java]-NO.20.Exam.1.Java.1.001-[1z0-807] Style:EBook Series:Java Since:2017-10- ...

  9. 【Other】最近在研究的, Java/Springboot/RPC/JPA等

    我的Springboot框架,欢迎关注: https://github.com/junneyang/common-web-starter Dubbo-大波-服务化框架 dubbo_百度搜索 Dubbo ...

随机推荐

  1. PDF解决方案(3)--PDF转SWF

    相关专题链接 PDF解决方案(1)--文件上传 PDF解决方案(2)--文件转PDF PDF解决方案(3)--PDF转SWF PDF解决方案(4)--在线浏览 前言:上一篇中介绍了上传的文件转PDF, ...

  2. css技巧--整理(1)

    1.文字描边 -webkit-text-shadow:#be8ef8 2px 0 1px,#be8ef8 0 2px 1px,#be8ef8 -2px 0 1px,#be8ef8 0 -2px 1px ...

  3. J2EE总结(2)——Servlet/JSP

    Servlet/JSP Servlet定义:部署在java的Webserver上的组件.整个java服务端程序都构建在Servlet之上,以多线程方式提 供服务,具有效率高.可扩展,可移植的特点. J ...

  4. 3DMax的OFusion插件的使用问题

    使用OFusion将3D max导出到现场Ogre的Mesh该方法是经常使用的非.的一些问题,在这里为方便摘要. 1.OFusion得到: http://download.csdn.net/detai ...

  5. Android Fragement学习笔记(三)----PreferenceFragment使用

    我相信每个人都Perference大家都比较熟悉,这就是我们常说的偏好,首选项设置,一些数据可以保存.例如,一些元件的,我们使用上次.希望下次启动后仍然生效,烦.一般这个时候我们便会使用perfere ...

  6. Hypeiron Planning/Essbase修改规划类型名称

    1.修改planning关系库 1.1--修改Plan_type,例如将type_name “Plan1”修改为”Plan1ts”,提交 SELECT * FROM hsp_plan_type FOR ...

  7. 题目要求:建立一个类Str,将一个正整数转换成相应的字符串,例如整数3456转换为字符串"3456".

    题目要求:建立一个类Str,将一个正整数转换成相应的字符串,例如整数3456转换为字符串"3456". 关键:怎么将一个数字转换为字符? [cpp] view plaincopy ...

  8. Ibatis ISqlMapper工厂类案例

    namespace Model{ public class MapperFactory { //声明一个ISqlMapper接口类型的数据映射器 _mapper,其初始值为null private s ...

  9. readonly和const的区别

    readonly与const的区别1.const常量在声明的同时必须赋值,readonly在声明时可以不赋值2.readonly只能在声明时或在构造方法中赋值(readonly的成员变量可以根据调用不 ...

  10. Wookmark-jQuery-master 瀑布流插件

    Wookmark-jQuery-master 瀑布流插件使用介绍,含个人测试DEMO 要求 必备知识 本文要求基本了解 Html/CSS,  JavaScript/JQuery. 开发环境 Dream ...