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 還是報一樣的錯
安裝了AccessDatebaseEngine.exe,那麼你應該用ACE 12.0或者ACE 14.0而不是OLEDB 12.0,再說OLEDB最高也就是4.0