C#代码
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 System.Data;
using MySql.Data.MySqlClient;
namespace LBImqP
{
public partial class Form1 : Form
{
MySqlConnection con = new MySqlConnection(@"Data Source=localhost;port=3306;Initial Catalog=lbimqp;User ID=root;password='server1234'");
int i;
public Form1()
{
InitializeComponent();
}
private void login_Click(object sender, EventArgs e)
{
i = 0;
con.Open();
MySqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO `login` VALUES (`username`, `password`)";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
i = Convert.ToInt32(dt.Rows.Count.ToString());
if (i == 0)
{
wrong.Text = "Username or password is wrong!";
}
else
{
this.Hide();
mainscreen ms = new mainscreen();
ms.Show();
}
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
用户是在mysql数据库中创建的。 这是一张图片: Mysql
每次我需要登录系统时都说用户名或密码错误,我不明白为什么。我希望有一个人可以帮助我。谢谢。 :)