c#操作access数据库
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace AddressList
{
public partial class FrmAccessUse : Form
{
public FrmAccessUse()
{
InitializeComponent();
}
#region 调用access标准方法
// using System.Data.OleDb;
// using System.Data;
// 连接字符串:String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=product.mdb";
// 建立连接:OleDbConnection connection = new OleDbConnection(connectionString);
// 使用OleDbCommand类来执行Sql语句:
// OleDbCommand cmd = new OleDbCommand(sql, connection);
// connection.Open();
// cmd.ExecuteNonQuery();
#endregion
#region 连接字符串
//string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\程序书籍软件\c#程序代码\access数据库操作\addressList.mdb"; //绝对路径
string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Environment.CurrentDirectory+"\\addressList.mdb"; //相对路径
#endregion
#region 查询
private void tsbQuery_Click(object sender, EventArgs e)
{
query();
}
#endregion
#region 查询语句
private void query()
{
try
{
gridView1.Columns.Clear();
OleDbConnection connet1 = new OleDbConnection(strcon);
string sql = "select * from new1";
connet1.Open();
OleDbDataAdapter myadapter = new OleDbDataAdapter();
DataSet ds = new DataSet();
myadapter.SelectCommand = new OleDbCommand(sql, connet1);
myadapter.Fill(ds);
gridControl1.DataSource = ds.Tables[0];
connet1.Close();
相关文档:
——————————————————————————————————
在c#中如何使用以前c++的.lib库和.h头文件
zhujiang_1977(朱江 ......
Take Equity Collection System as an example, Some other office collegues want to access it from home without VPN, The way to check is:
1. Check if it's limited in network, this needs to confirm with network people
2. If the step 1 passed, get the external IP address of the system, map ......
string sql = "select a.orderId,a.UserName,b.CodeValue as Delivery ,a.DeliveryAddress,a.PhoneNum,c.CodeValue as Payment,d.CodeValue as OrderStatus,d.CodeValue as OrderStatusID,a.OrderTime,a.Merchant from (( m_Order a ";
sql += " left j ......
set adoCN =createobject("ADODB.CONNECTION")
set strCnn =createobject("ADODB.Recordset")
set rstSchema =createobject("ADODB.Recordset")
Dim I
dim n
str1 ......