| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 925 人关注过本帖
标题:为什么打开数据库失败?
取消只看楼主 加入收藏
ysf0181
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
结帖率:76.71%
收藏
 问题点数:0 回复次数:0 
为什么打开数据库失败?
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]]
搜索更多相关主题的帖子: 数据库 失败 
2008-01-24 22:26
快速回复:为什么打开数据库失败?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022220 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved