[mysql.data.mysqlclient.mysqlexception错误C#

问题描述 投票:0回答:1

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个回答
1
投票

该错误与C#无关,您具有错误消息中提到的错误的SQL查询语法:

SELECT * fromkullanıcılar其中子句KullanicıAdi='...

必须在其后的字段和参数列表

此外,请勿通过文本污染向查询添加参数-使用parameterized query

© www.soinside.com 2019 - 2024. All rights reserved.