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;//连接Access数据库
namespace Login
{
public partial class Form1 : Form
{
static public string username;//用于保存用户名
static public string password;
public Form1()
{
InitializeComponent();
}
//判断语句
private bool judge()
{
if (txt_username.Text == "")
return false;
if (txt_password.Text == "")
return false;
return true;
}
//登陆按钮的点击
private void btn_login_Click(object sender, EventArgs e)
{
if (!judge())
{
MessageBox.Show("请输入正确的的信息...");
return ;
}
//创建路径及数据名
string strPath = Application.StartupPath+"\\login.accdb";
//生成来连接数据库字符串
string oleCon = "provider=Microsoft.Jet.OLEDB.12.0;Data source=" + strPath;
//创建数据库连接
OleDbConnection conn = new OleDbConnection(oleCon);
//
conn.Open();
//SQL查询语句
string access = "select UserId,Password from user where UserId='" + this.txt_username.Text + "'and Password='" + this.txt_password.Text + "'";
OleDbCommand cmd = new OleDbCommand(access, conn);
OleDbDataReader hyw = cmd.ExecuteReader();
if (hyw.Read())
{
//在构造中我们的量就作为判断
username = txt_username.Text;
password = txt_password.Text;
//一旦连接成功了就弹出窗口
MessageBox.Show("登录成功!");
Form f2 = new Form2();
this.Hide();
f2.ShowDialog();
this.Dispose();
}
else
{
//信息错误,判断条件不成立
MessageBox.Show("输入用户密码错误");
}
}
}
}
报 未在本地计算机上注册“Microsoft.Jet.OLEDB.12.0”提供程序。???
后来我安装了AccessDatebaseEngine.exe 还是报一样的错