且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C#代码在Windows应用程序上连接Access数据库

更新时间:2023-10-21 12:51:46

使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Text;
使用System.Windows.Forms;
使用System.Data.OleDb;



命名空间urvesh
{
公共局部类Form1:Form
{
公共OleDbConnection con;
公共OleDbCommand com;
public DataSet ds;
公共OleDbDataAdapter dap;


公共Form1()
{
InitializeComponent();
}

私有无效btnlogin_Click(对象发送者,EventArgs e)
{
con = new OleDbConnection();
com = new OleDbCommand();
dap =新的OleDbDataAdapter();
ds = new DataSet();
con.ConnectionString = @"Provider = Microsoft.Jet.OLEDB.4.0; Data Source = E:\ airbilling \ airbilling \ airbilling \ bill.mdb";
con.Open();

com.CommandText =从登录名中选择*,其中usename =''" + txtusername.Text +''AND password =""+ txtpassword.Text +"'',con;
com.ExecuteReader();
con.Close();

MessageBox.Show("login");
}
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 urvesh
{
public partial class Form1 : Form
{
public OleDbConnection con;
public OleDbCommand com;
public DataSet ds;
public OleDbDataAdapter dap;


public Form1()
{
InitializeComponent();
}

private void btnlogin_Click(object sender, EventArgs e)
{
con = new OleDbConnection();
com = new OleDbCommand();
dap = new OleDbDataAdapter();
ds = new DataSet();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\airbilling\airbilling\airbilling\bill.mdb";
con.Open();

com.CommandText="select * from login where usename=''"+ txtusername.Text +"'' AND password=''"+txtpassword.Text+"'',con";
com.ExecuteReader();
con.Close();

MessageBox.Show("login");
}