【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 ...
随机推荐
- GNU中宏定义对可变参数的支持(引自百度)
http://zhidao.baidu.com/question/125413478.html 问:#define PDEBUG(fmt,args...) fprintf(stderr,fmt, ## ...
- Python开发环境Wing IDE 5.0测试第八版发布
Wing IDE是著名的Python开发工具,是Wingware公司的主要产品.从1999年起,Wingware公司便开始专注于Python开发设计.Wing IDE在十几年的发展中,不管完善.其强大 ...
- POJ 3602 Typographical Ligatures
[题意简述]:题意就是输入一串字符串,问我们有多少种不同的字符,也就是说出现过一次的字符,下次就不记到种数中了,特别的有 ff, fi ,fl ,ffi ,ffl,'',``, 这几个每一个算是一种 ...
- 四个漂亮的CSS样式表
1. 单像素边框CSS表格 这是一个非经常常使用的表格样式. 源码: <!-- CSS goes in the document HEAD or added to your external s ...
- [ext/iconv/iconv.lo] Error 1
办法1: wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz tar -zxvf libiconv-1.13.1.tar.g ...
- Apworks到底是什么?
Apworks到底是什么? 简介 Apworks是一款基于Microsoft .NET的面向领域驱动的企业级应用程序开发框架,它适用于以领域模型为核心的企业级系统的开发和集成.Apworks不仅能够很 ...
- 排序算法的C#实现
8种主要排序算法的C#实现 新的一年到了,很多园友都辞职要去追求更好的工作环境,我也是其中一个,呵呵! 最近闲暇的时候我开始重温一些常用的算法.老早就买了<算法导论>,一直都没啃下去. ...
- vj1011:记忆化搜索
vj1011:记忆化搜索 这题就是很简单的记忆化搜索即可,和经典题目滑雪简直一模一样 对于记忆化搜索,我也是暑假看了ccy大神的题解才有所领悟的 其实也就是DFS+mark 主要的部分 int sea ...
- cocos2d-x-2.2.0_win7+vs2010
cocos2d-x-2.2.0_win7+vs2010搭建_eclipse+ndk-r9+cygwin搭建_教程以及编译问题汇总 声明:我是才用c/c++和cocos2d-x的如果有错误欢迎指出 文章 ...
- Google Adsense(Google网站联盟)广告申请指南
Google AdSense 是一种获取收入的快速简便的方法,适合于各种规模的网站发布商.它可以在网站的内容网页上展示相关性较高的 Google 广告,并且这些广告不会过分夸张醒目.由于所展示的广告同 ...