using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;//引入MySql数据接口
namespace HWork3_1单词记忆学习测试系统
{
public partial class Form12 : Form
{
public Form12()
{
InitializeComponent();
}
private void Form12_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)//登录
{
string name = textBox1.Text.Trim();
string password = textBox2.Text.Trim();
//连接mysql数据库
MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();
sb.Server = "127.0.0.1";
sb.Port = 3306;
sb.Database = "englishlearningsystem";
sb.UserID = "root";
sb.Password = "root";
sb.CharacterSet = "gb2312";
MySqlConnection con = new MySqlConnection(sb.ConnectionString);//实例化连接
con.Open();
if (radioButton1.Checked == true)//用户表
{
String query = "select * from user where uname='" + name + "' and upassword='" + password + "'";//向数据库服务器发送指令
MySqlCommand cmd = new MySqlCommand(query, con);
//执行结果赋值到dr,dr为只读
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Form1 form1 = new Form1();
form1.Show();
}
else if (name == "" || password == "")
{
MessageBox.Show("对不起,用户名或密码为空,请重新输入!", "输入为空", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning);
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;//引入MySql数据接口
namespace HWork3_1单词记忆学习测试系统
{
public partial class Form12 : Form
{
public Form12()
{
InitializeComponent();
}
private void Form12_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)//登录
{
string name = textBox1.Text.Trim();
string password = textBox2.Text.Trim();
//连接mysql数据库
MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();
sb.Server = "127.0.0.1";
sb.Port = 3306;
sb.Database = "englishlearningsystem";
sb.UserID = "root";
sb.Password = "root";
sb.CharacterSet = "gb2312";
MySqlConnection con = new MySqlConnection(sb.ConnectionString);//实例化连接
con.Open();
if (radioButton1.Checked == true)//用户表
{
String query = "select * from user where uname='" + name + "' and upassword='" + password + "'";//向数据库服务器发送指令
MySqlCommand cmd = new MySqlCommand(query, con);
//执行结果赋值到dr,dr为只读
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Form1 form1 = new Form1();
form1.Show();
}
else if (name == "" || password == "")
{
MessageBox.Show("对不起,用户名或密码为空,请重新输入!", "输入为空", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Warning);
}

这是一个使用VS2010和C#实现的MySQL数据库用户登录和注册功能。代码中,根据用户选择的用户表或管理员表进行数据验证,如果输入的用户名或密码匹配,则进入相应界面;否则,提示用户重新输入。同时提供了注册新用户的功能,检查用户名是否已存在,并插入新记录。

2万+

被折叠的 条评论
为什么被折叠?



