如何使用C#代码在Windows应用程序上连接Access数据库 [英] how to connect access database on windows application with C# code

查看:201
本文介绍了如何使用C#代码在Windows应用程序上连接Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




嘿,我想用C#在Windows应用程序上连接Access数据库.
我尽力了,但是有一些错误.
代码是..
使用系统;
使用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");
}

因此,如果您有一些逻辑或代码,请发送给我.
black_ocean8007@yahoo.com

谢谢.

Hi,


Hey i want to connect access database with windows application on C#.
i tray my best but there are some mistake.
code are..
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");
}

so if u have some logic or code then sent me on.
black_ocean8007@yahoo.com

Thank You.

推荐答案

使用系统;
使用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");
}


这篇关于如何使用C#代码在Windows应用程序上连接Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆