【C#】Creating/Querying/Modifying the .mdb databases
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的更多相关文章
- 【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 解决方法,依次输 ...
- 【c#】ADO操作Access的mdb数据库只能读不能修改的解决方法
在使用ACCESS数据库时连接字符串如 string strcon=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Access操作\简易 ...
- 【贪心/DP/单调队列】【CF1029B】Creating the Contest
Description 给你一个单调不下降的长度为n的序列,请你找出一个最长的子序列,满足找出的子序列中,\(A_i<=A_{i-1}~\times~2\),其中i为下标,A为找出的子序列.对于 ...
- 【CF1029B】Creating the Contest(贪心)
题意: n<=2e5 思路:可以证明答案一定是极长的一段中取最大值 #include<cstdio> #include<cstring> #include<stri ...
- 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;
一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...
- 【CodeChef】Querying on a Grid(分治,最短路)
[CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最 ...
- 【12c】扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE
[12c]扩展数据类型(Extended Data Types)-- MAX_STRING_SIZE 在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的 ...
- 【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- ...
- 【Other】最近在研究的, Java/Springboot/RPC/JPA等
我的Springboot框架,欢迎关注: https://github.com/junneyang/common-web-starter Dubbo-大波-服务化框架 dubbo_百度搜索 Dubbo ...
随机推荐
- 纯Lambda实现斐波那契数列
还需要考虑溢出等问题,主要无事写着玩 Func<float, float, float> a = (arg1, arg2) => 0f;//init ; a = (lastNumbe ...
- leetcode [64] merge tow sorted lists
之前忘记记录这题了,现在补上. 合并两个有序的list,要求是: Merge two sorted linked lists and return it as a new list. The new ...
- 依据道路的shape获得high_cross和low_cross
如图所看到的:怎样依据提供的道路的shape file获得该路的high cross和low cross 所谓的high cross就是图中的king st这条路,low cross是Gravers ...
- 【Linux 工作经常使用命令
】
1, 批量杀某个程序 比方某个程序叫 url_info.py, 起了若干个进程 . 高速查杀. 先查看 ps aux | grep url_info.py 确认没问题 ,能够杀,则批量kill ps ...
- 使用hibernate在5秒内插入11万条数据,你觉得可能吗?
需求是这样的,需要查询某几个表的数据,然后插入到另外一个表. 一看到需求,很多人都会用hibernate去把这些数据都查询出来,然后放到list中, 然后再用for循环之类的进行遍历,一条一条的取出数 ...
- bitnami redmine安装、配置、备份、恢复(这篇文章靠谱)
bitnami redmine安装.配置.备份.恢复 2012-12-17 12:33 2596人阅读 评论(0) 收藏 举报 1. 安装时语言选择英文,不可以选择中文,否则不能正常运行,可以在账户里 ...
- des和Rijndael加密
------------IV的作用: 为了保证数据的安全,.NET基类库中提供的私钥算法类使用称作密码块链(CBC,Cipher Block Chaining)的链模式,算法使用一个密钥和一个初始化向 ...
- MVC 控制器
ASP.NET MVC控制器(一) 前言 在路由的篇章中讲解了路由的作用,讲着讲着就到了控制器部分了,从本篇开始来讲解MVC中的控制器,控制器是怎么来的?MVC框架对它做了什么?以及前面有的篇幅所留的 ...
- 基于嵌入式OS的任务设计-----任务划分
在<前后台系统VS嵌入式OS,何时该上OS?>一文中介绍了何时应该将OS应用于嵌入式设计中,本文将介绍基于OS的任务设计,一般来说,应用程序设计包括两个方面,一个是业务逻辑的设计,另一个是 ...
- CompareValues标签对Model中的属性进行验证
在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证 在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个 ...