Access数据库的连接方法
这两天开始学习ACCESS数据库的连接,感觉不是特别的顺手,对数据库的连接的整个过程还不是特别的了解。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string strPath = Application.StartupPath + "\\ip.mdb";
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:DataBase Password='" + this.textBox1.Text + "'; User Id=admin;Data source=" + strPath;
OleDbConnection oleCon = new OleDbConnection(ConStr);
OleDbDataAdapter oleDap = new OleDbDataAdapter("select * from ip", oleCon);
DataSet ds = new DataSet();
oleDap.Fill(ds, "ip");
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
oleCon.Close();
oleCon.Dispose();
}
catch (Exception ey)
{
MessageBox.Show(ey.Message);
}
}
}
}
相关文档:
DELPHI中操作ACCESS数据库(建立.mdb文件,压缩数据库)
以下代码在WIN2K,D6,MDAC2.6下测试通过,
编译好的程序在WIN98第二版无ACCESS环境下运行成功.
//声明连接字符串
Const
SConnectionString
= 'Provider=M ......
用Cdbl()试试
CDbl(str) --> 双精度
CInt(str) --> 整型
CLng(str) --> 长整型
CSng(str) --> 单精度
CDate(str) --> 日期型 ......
由于工作需要,使用ACCESS数据库存储港口周围AIS设备接收到的船舶数据。由于在全国很多港口有采集点,因此,数据量很大,每三分钟存储一次数据的话,那么一次将有2000多新的船位数据。这些数据入库后,数据库文件大小将新增1M到2M左右。根据这个频率,一个小时数据库文件将增加40M,一天就是960M。
为了提高数据库效率,我 ......
1.now() 获取当前时间;
2.关于Access内部的模糊查询:
在C#里写应写成 Select * from Table Where Name Like '%ABC%'
Select * from Table Where Name Like '_AB ......
create table(access环境下)自动编号类型的写法
方法一:
create table tablename(id counter constraint primarykey primary key)
需要注意的地方是:第二个primary中间有空格,另外,关键字不区分大小写.
方法二:
create table mytb (id autoincrement(25,1) primary key,age int)
或
create table testtb (id aut ......