• 大小: 8.2MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-23
  • 语言: C#
  • 标签: C#  MySql  C#界面  

资源简介

使用C#连接MySql数据库,如果下载使用要连接自己的数据库进行配置,还要更改相关表名,可作参考

资源截图

代码片段和文件信息

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Refectory
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public Form2 w2;
        public Form3 w3;
        public Form8 w8;
        private int count = 0;
        private void Form1_Load(object sender EventArgs e)
        {
            w2 = new Form2();
            w3 = new Form3();
            w8 = new Form8();
        }
        public static string id;
        public static string password;
        public static string name;
        private void button1_Click(object sender EventArgs e)//登录按钮
        {
            try
            {
                if (textBox1.Text.Trim() == ““)
                {
                    MessageBox.Show(“账号不能为空请输入账号!“);
                    textBox1.Focus();
                    return;
                }
                else if (textBox2.Text.Trim() == ““)
                {
                    MessageBox.Show(“密码不能为空请输入密码!“);
                    textBox2.Focus();
                    return;
                }
                else
                {
                    string str = “Server=localhost;User ID=root;Password=123456;Database=my;CharSet=gbk“;
                    MySqlConnection con = new MySqlConnection(str);//实例化链接
                    con.Open();//开启连接
                    MySqlCommand cmd = con.CreateCommand();
                    cmd.CommandText = “select * from m_register2 where Id=‘“ + textBox1.Text + “‘“;
                    MySqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        string dbpassword = reader.GetString(reader.GetOrdinal(“Password“));
                        id = reader.GetString(reader.GetOrdinal(“Id“));
                        name = reader.GetString(reader.GetOrdinal(“Name“));
                        password = dbpassword;
                        if (textBox2.Text == dbpassword)
                        {
                            this.Hide();
                            w2.ShowDialog();
                            
                        }
                        else
                        {
                            MessageBox.Show(“密码错误,请重新输入密码!“);
                            count++;
                            if (count > 3)
                            {
                                button1.Enabled = false;
                            }
                            else
                            {
                                button2.Enabled = true;
                            }

                        }
                        con.Close();
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-05 18:23  Refectory\
     目录           0  2017-12-23 20:13  Refectory\.vs\
     目录           0  2017-12-23 20:13  Refectory\.vs\Refectory\
     目录           0  2017-12-27 19:55  Refectory\.vs\Refectory\v14\
     文件       71680  2018-01-24 19:48  Refectory\.vs\Refectory\v14\.suo
     目录           0  2018-01-24 19:48  Refectory\Refectory\
     文件         189  2017-12-23 20:13  Refectory\Refectory\App.config
     文件        5423  2018-01-03 08:51  Refectory\Refectory\Form1.Designer.cs
     文件        3612  2018-01-24 19:48  Refectory\Refectory\Form1.cs
     文件       73668  2018-01-03 08:51  Refectory\Refectory\Form1.resx
     文件        4046  2018-01-05 22:27  Refectory\Refectory\Form10.Designer.cs
     文件        1571  2018-01-05 22:27  Refectory\Refectory\Form10.cs
     文件        5817  2018-01-05 22:27  Refectory\Refectory\Form10.resx
     文件        3673  2018-01-03 21:27  Refectory\Refectory\Form11.Designer.cs
     文件        1545  2018-01-04 17:23  Refectory\Refectory\Form11.cs
     文件        5817  2018-01-03 21:27  Refectory\Refectory\Form11.resx
     文件       35909  2018-01-05 22:31  Refectory\Refectory\Form2.Designer.cs
     文件       13854  2018-01-24 19:48  Refectory\Refectory\Form2.cs
     文件       60534  2018-01-05 22:31  Refectory\Refectory\Form2.resx
     文件       11138  2018-01-05 22:27  Refectory\Refectory\Form3.Designer.cs
     文件        2862  2018-01-05 22:27  Refectory\Refectory\Form3.cs
     文件        5817  2018-01-05 22:27  Refectory\Refectory\Form3.resx
     文件       13762  2018-01-05 22:27  Refectory\Refectory\Form4.Designer.cs
     文件        4205  2018-01-24 19:48  Refectory\Refectory\Form4.cs
     文件        5817  2018-01-05 22:27  Refectory\Refectory\Form4.resx
     文件       12363  2018-01-05 22:27  Refectory\Refectory\Form5.Designer.cs
     文件        4138  2018-01-22 17:35  Refectory\Refectory\Form5.cs
     文件        5817  2018-01-05 22:27  Refectory\Refectory\Form5.resx
     文件        7777  2018-01-05 22:27  Refectory\Refectory\Form6.Designer.cs
     文件        3244  2018-01-22 17:35  Refectory\Refectory\Form6.cs
     文件        5817  2018-01-05 22:27  Refectory\Refectory\Form6.resx
............此处省略160个文件信息

评论

共有 条评论