using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Windows.Forms;namespace 成语词典
{
public partial class loginForm : Form
{
public loginForm()
{
InitializeComponent();
} string str = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = D:\\showay.mdb";
OleDbConnection conn = new OleDbConnection();
OleDbDataReader result = null;
public bool loginus(string un, string pw)
{
conn.ConnectionString = str;
string sql = "select*from 用户表1 where 用户名 = '"+un+" 'and 密码 = '"+pw +"'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.Connection.Open();
try
{
result = cmd.ExecuteReader(); }
catch(Exception )
{
MessageBox.Show("对不起!查询数据失败!","提示");
}
if(result !=null)
{
if (result.Read())
{ return true; };
}
result.Close();
cmd.Connection.Close();
return false;
} private void button1_Click(object sender, EventArgs e)
{
string n = textBox1.Text.Trim();
string p = textBox2.Text.Trim();
if ((textBox1.Text != " ") & (textBox2.Text != " "))
{
if (loginus(n, p) == false)
{
MessageBox.Show("用户密码错误!");
return ;
}
DialogResult = DialogResult .OK ;
this .Hide ();
}
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
这是个用于用户登录的,我用的是Access数据库,我做了个以showay命名的数据库,里面放了密码,可执行时老提示找不到数据库文件,好纠结哦希望哪位指点指点。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Windows.Forms;namespace 成语词典
{
public partial class loginForm : Form
{
public loginForm()
{
InitializeComponent();
} string str = "Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = D:\\showay.mdb";
OleDbConnection conn = new OleDbConnection();
OleDbDataReader result = null;
public bool loginus(string un, string pw)
{
conn.ConnectionString = str;
string sql = "select*from 用户表1 where 用户名 = '"+un+" 'and 密码 = '"+pw +"'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.Connection.Open();
try
{
result = cmd.ExecuteReader(); }
catch(Exception )
{
MessageBox.Show("对不起!查询数据失败!","提示");
}
if(result !=null)
{
if (result.Read())
{ return true; };
}
result.Close();
cmd.Connection.Close();
return false;
} private void button1_Click(object sender, EventArgs e)
{
string n = textBox1.Text.Trim();
string p = textBox2.Text.Trim();
if ((textBox1.Text != " ") & (textBox2.Text != " "))
{
if (loginus(n, p) == false)
{
MessageBox.Show("用户密码错误!");
return ;
}
DialogResult = DialogResult .OK ;
this .Hide ();
}
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
这是个用于用户登录的,我用的是Access数据库,我做了个以showay命名的数据库,里面放了密码,可执行时老提示找不到数据库文件,好纠结哦希望哪位指点指点。
你的sql语句该有空格的地方注意要有空格
if(result !=null)
{
if (result.Read())
{ return true; };
}
result.Close();
cmd.Connection.Close();
return false;
}
public bool loginus(string un, string pw)