
请问用Visual Studio 2005怎么编写一个登陆窗体?
我想编一个登陆窗体用c#数据库database1.mdf是VisualStudio2005中的有个user表表属性有name和psw在登陆中输入姓名和密码点登陆后与储存在...
我想编一个登陆窗体 用c# 数据库database1.mdf是Visual Studio 2005中的 有个user表 表属性有name和psw 在登陆中输入姓名和密码 点登陆后 与储存在user表里的一致就能进入,错误就提示错误信息 不一致就退出。。。
展开
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;//连接Access数据库必须
namespace //随便
{
public partial class Login : Form//登陆窗体
{
public Login()//构造函数
{
InitializeComponent();
}
public bool blCanLogin;//设置参数如果为true,就登陆,否则放弃登陆
OleDbConnection connection1 = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = C:\\db1.mdb");//连接数据库db1.mdb 在c盘根目录
private void button1_Click(object sender, EventArgs e)
//定义登陆按钮事件
{
blCanLogin = false;//初始值为false
string sql = "select name,passwd from userinfo";//从userinfo表中查询name(用户名)和passwd(密码)
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;
this.Close();
return;
}
}
MessageBox.Show("你输入的用户名或密码不正确!");
connection1.Close();
return;
}
else
MessageBox.Show("密码不能为空");
return;
}
else
MessageBox.Show("用户名不能为空");
connection1.Close();
}
private void button2_Click(object sender, EventArgs e)
{
blCanLogin = false;
this.Close();
}
}
}

2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询