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. Windows在结构FTPserver

    同Windows8 案件,结构介绍 FTPserver脚步: 1.为Windows开启FTP功能:控制面板->程序->启用或关闭Windows功能.将下图所看到的的复选框选中 waterm ...

  2. CodeIgniter学习一:基础知识

    1. url片段(CI域名组成说明)        example.com/index.php/test/index   第一部分(test):控制器 第二部分(index):方法,动作 如果第二部分 ...

  3. mysql编码的那点事

    Mysql编码问题  在php页面可以向mysql插入英文字符,但就是不能插入中文字符,在cmd客户端也可从插入,这是困扰我两天的问题. 在网上找了很多资料,最终确定了是字符编码这个地方出现了问题,首 ...

  4. at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)

    最近在做一个WinForm的项目. 使用vs2013开发. 数据库使用的是oracle. 在本地写了一个webservice .测试正常.发布到服务器的时候.就是提示了错误. 打开服务器上的日志.看到 ...

  5. Android Intent 三解决

    Intent的接收处理: 1.Receiver报名 这之前已经被引入 然后看看剩下的两个接收功能上面. scheduleReceiver scheduleRegisteredReceiver: sch ...

  6. 【通过操作指针,与指针做函数參数&#39;实现字串在主串中出现的次数,然后将出现的部分依照要求进行替换 】

    #include<stdio.h> #include<stdlib.h> int strTime(const char *str1, const char *str2, int ...

  7. Hibernate进化史-------Hibernate概要

    一个.Hibernate概要 什么是Hibernate呢?首先,Hibernate是数据持久层的一个轻量级框架.实现了ORMapping原理(Object Relational Mapping). 在 ...

  8. Web面试之JQuery

    程序员Web面试之JQuery   又到了一年一度的毕业季了,青春散场,却等待下一场开幕. 在求职大军中,IT行业的程序员.码农是工科类大学生的热门选择之一, 尤其是近几年Web的如火如荼,更是吸引了 ...

  9. IP地址爬取

    ip_spider.py= = = #!/usr/bin/python # coding: utf-8 import os import sys import requests import re i ...

  10. Light, more light - PC110701

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10110.html 原创:Ligh ...