1.使用楼主所指用的路径,一般数据库文件放在和exe文件一个目录下,调试时对应的是debug目
录2.你所使用的登录判断方式很容易被SQL 注入攻击

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.OleDb;namespace WindowsApplication1
    {
    public class MyTest : Form
    {
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.TextBox textBox2;
    private System.ComponentModel.Container components = null;
    public MyTest()
    {
    InitializeComponent();
    } protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.textBox2 = new System.Windows.Forms.TextBox();
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(16, 80);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "";
    // 
    // textBox2
    // 
    this.textBox2.Location = new System.Drawing.Point(136, 80);
    this.textBox2.Name = "textBox2";
    this.textBox2.PasswordChar = '*';
    this.textBox2.TabIndex = 1;
    this.textBox2.Text = "";
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(24, 168);
    this.button1.Name = "button1";
    this.button1.TabIndex = 2;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.Location = new System.Drawing.Point(136, 168);
    this.button2.Name = "button2";
    this.button2.TabIndex = 3;
    this.button2.Text = "button2";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // MyTest
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.button2);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.textBox2);
    this.Controls.Add(this.textBox1);
    this.Name = "MyTest";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new MyTest());
    } private void button2_Click(object sender, EventArgs e)
    {
    this.Close();
    } private void button1_Click(object sender, EventArgs e)
    {
    try
    {
    //   OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=e:\\exam.mdb");
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + @"\exam.mdb");
    string str = "select * from admin WHERE userid='"+this.textBox1.Text.Trim()+"'";
    OleDbCommand comm = new OleDbCommand(str, conn); conn.Open(); OleDbDataReader dr = comm.ExecuteReader();

    bool flag = false;
    while(dr.Read())
    {
    if(dr["userid"].ToString()==this.textBox1.Text.ToString())
    {
    if (dr["password"].ToString() == this.textBox2.Text.ToString())
    {
    MessageBox.Show("你是合法用户");
    }
    else
    {
    MessageBox.Show("密码错误!");
    this.textBox2.Focus();
    this.textBox2.SelectAll();
    }
    flag = true;
    }

    }
    if (flag==false)
    MessageBox.Show("此用户不存在,是否注册!"); conn.Close(); }
    catch(Exception ee)
    { MessageBox.Show(ee.Message);

    } }
    }
      

  2.   

    1.拼Application.StartupPath 的时候,前后不该加单引号
    OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + @"\exam.mdb");2.判断OleDbDataReader的对象dr是否还有记录用的是dr.Read()方法3.只有遍历了数据库所有的记录,才能判断出用户是否存在,所以
    MessageBox.Show("此用户不存在,是否注册!");应该放在循环之外其他的小问题还很多,就不一一细说了
      

  3.   

    高歌.首先谢谢你,那两天不是我的浏览器问题还是什么原因.我登陆不上来了,提示不正确的验证,可我的ID和密码及验证码都是正确的,不知道,我把浏览器又重新搞了一下.麻烦死了.说我的工作吧,我把你写的代码复制过去之后,它提示说MyTest前少了partial
    我加上之后,又出现了七处错误说:按钮和文本已经声明?
    (我把我的代码注释了)
    如果方便留下您的联系方式吧(以消息形式发给我)或加我QQ:253530133谢谢,以后向你多请教