0

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

        }

    }
}

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.