为什么打开数据库失败?
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 叶影电脑维护系统
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
public bool blCanLogin;
OleDbConnection connection1 = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = d:\\ysf.mdb");
private void button1_Click(object sender, EventArgs e)
{
blCanLogin = false;
string sql = "select username,password from admin";
DataRow myRow;
connection1.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(sql, connection1);
DataSet ds = new DataSet();
adp.Fill(ds,"user");
if (textBox1.Text.Trim() != "")
{
if (textBox2.Text.Trim() != "")
{
for (int i = 0; i < ds.Tables["user"].Rows.Count; i++)
{
myRow = ds.Tables["user"].Rows[i];
if (myRow[0].ToString().Trim() == textBox1.Text.ToString().Trim() && myRow[1].ToString().Trim() == textBox2.Text.ToString().Trim())
{
blCanLogin = true;
MainForm mainForm = new MainForm();
// mainForm.myname = this.textBox1.Text.Trim();
return;
}
connection1.Close();
}
MessageBox.Show("你输入的用户名或密码不正确!");
connection1.Close();
return;
}
else
MessageBox.Show("密码不能为空");
connection1.Close();
return;
}
MessageBox.Show("用户名不能为空");
connection1.Close();
}
private void button2_Click(object sender, EventArgs e)
{
blCanLogin = false;
this.Close();
}
}
}
我在D盘下有了ysf.mdb 这个数据库了。也有相应的表及字段!!!
[[italic] 本帖最后由 ysf0181 于 2008-1-24 22:27 编辑 [/italic]]