【问题标题】:mysql.data.mysqlclient.mysqlexception Error C#mysql.data.mysqlclient.mysqlexception 错误 C#
【发布时间】:2020-05-04 13:20:21
【问题描述】:

enter image description here

我正在使用 Visual Studio 编写程序。我在登录表单中收到错误。当我搜索互联网。我找不到任何解决方法。我使用 vb.net 时没有任何问题。我在使用 C# 时看到此错误。 为什么我看到这个错误? 我的代码:

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;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        MySqlConnection bag = new MySqlConnection("Allow User Variables=True;Server=localhost;Database=gamesh;Uid=root;Pwd='';");

        public Form1()
        {
            InitializeComponent();

        }

        private void Button1_Click(object sender, EventArgs e)
        {
            bag.Open();
            MySqlCommand komut = new MySqlCommand("SELECT * from kullanıcılar where clause KullanicıAdi='" + TextBox1.Text.Trim() + "' and Sifre='" + TextBox2.Text.Trim() + "'", bag);
            MySqlDataReader dr = komut.ExecuteReader();
            if (dr.Read())
            {
                MessageBox.Show("Hoşgeldiniz");
            }
            else
            {
                MessageBox.Show("Hatalı Giriş");
            }
            bag.Close();

        }

    }
}

【问题讨论】:

    标签: mysql database exception mysql-error-1064 login-script


    【解决方案1】:

    该错误与C#无关,您的SQL查询语法不正确,如错误消息中所述:

    SELECT * from kullanıcılar where clause KullanicıAdi='...

    WHERE 后面必须跟一系列字段和参数

    另外,不要通过文本连接向查询添加参数 - 使用 parameterized query

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多