Access的DBHelper.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
namespace TaobaoDAL
{
public class DBHelper
{
//引导数据库连接数据库调用Web.Config文件
private static OleDbConnection connection;
//创建连接|DataDirectory|\SchoolDB.mdb
public static OleDbConnection Connection
{//Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.mappath("tushu.mdb")";Persist Security Info=False
get
{
OleDbConnection myConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\taobao.mdb");
string connectionString = myConn.ConnectionString;
if (connection == null)
{
connection = new OleDbConnection(connectionString);
//打开连接
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}
//(无参)返回执行的行数(删除修改更新)
public static int ExecuteCommand(string safeSql)
{
OleDbCommand cmd = new OleDbCommand(safeSql, Connection);
int result = cmd.ExecuteNonQuery();
return result;
}
//(有参)
public static int ExecuteCommand(string sql, params OleDbParameter[] values)
{
OleDbCommand cmd = new OleDbCommand(sql, Connection);
cmd.Parameters.AddRange(values);
return cmd.ExecuteNonQuery();
相关文档:
用Cdbl()试试
CDbl(str) --> 双精度
CInt(str) --> 整型
CLng(str) --> 长整型
CSng(str) --> 单精度
CDate(str) --> 日期型 ......
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.comboBox2.Items.Clear();
switch(this.comboBox1.SelectedIndex)
  ......
1.now() 获取当前时间;
2.关于Access内部的模糊查询:
在C#里写应写成 Select * from Table Where Name Like '%ABC%'
Select * from Table Where Name Like '_AB ......
最后在一位大侠的BLOG上看到
右击“我的电脑”。单击“属性”。
在“系统属性”中单击“高级”。
在“性能”中单击“设置”。
在“性能选项”中单击“数据执行保护”。
单击“添加”。选择要运行的程序。
OK。就这么简单 ......
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 ......