Semih Çam
Semih Çam

Reputation: 1

mysql.data.mysqlclient.mysqlexception Error C#

enter image description here

I'm coding a program using visual studio. I get an error in the login form. When I searched the internet. I could not find any fix. I didn't have any problems when I used vb.net. I see this error when I use C#. why i see this error? My code:

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();

        }

    }
}

Upvotes: 0

Views: 449

Answers (1)

basic
basic

Reputation: 11968

The error has nothing to do with C #, you have an incorrect SQL query syntax as mentioned in the error message:

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

WHERE must be followed by a list of fields and parameters

Also, do not add parameters to the query by text contatenation - use a parameterized query

Upvotes: 1

Related Questions