易截截图软件、单文件、免安装、纯绿色、仅160KB

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);
}
}
}
}


相关文档:

ACCESS里面创建带参数的存储过程

需要注意的是page_load里面的创建存储过程只能执行一次,如果第二次还要创建同名的话会提示错误信息“存储过程已经存在。”,其实加个判断就行了。懒得加了,只是用来试验一下。
调试环境 ASP.NET 2.0(编译工具VS2008),代码C#,access版本2003
protected void Page_Load(object sender, EventArgs e)
{
Ol ......

C#中使用DataTable显示Access数据库中文件列表


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
             this.comboBox2.Items.Clear();
            switch(this.comboBox1.SelectedIndex)
       ......

access 操作

1.now() 获取当前时间;
2.关于Access内部的模糊查询:
在C#里写应写成 Select * from Table Where Name Like '%ABC%' 
                        Select * from Table Where Name Like '_AB ......

create table(access环境下)自动编号类型的写法

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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号