0

I'm trying to connect my application with mysql server using localhost. The problem I'm facing is beyond my understanding. I've tried searching it but could not find any solution.

Error showing:

"Keyword not supported: 'uid'";

Below is the code:

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.CData.MySQL;
using MySql.Data.MySqlClient;



namespace DataAccess
{
    public partial class Form1 : Form
    {

        public Form1()
        {

            InitializeComponent();
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            MySQLConnection connection;

            String server = "localhost", database = "Student", userid = "root", password = "12345";
            String connectionString = "SERVER = " + server + ";" + "DATABASE = " + database + ";" + "USERID =" + userid + ";" + "PASSWORD = " + password + ";";

            String std_name = textBox1.Text, std_program = comboBox1.Text, std_department = comboBox2.Text;
            int std_age = Convert.ToInt32(textBox2.Text);
         //   MySQLDataAdapter mda = new MySQLDataAdapter("Insert into student.registration(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)", connection);
            connection = new MySQLConnection(connectionString);
            MySQLCommand cmd;
            connection.Open();

            try
            {
                cmd = connection.CreateCommand();
                cmd.CommandText = "Insert into Student(Name, Age, Program, Department) Values(@std_name,@std_age,@std_program,@std_department)";
                cmd.ExecuteNonQuery();
                MessageBox.Show("Record Successfully Entered!");
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();

                }
            }
        }
    }
}
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Mikka
  • 55
  • 1
  • 7
  • What's the error? Have you granted root user the proper access? Refer to http://stackoverflow.com/questions/8484722/access-denied-for-user-rootlocalhost-while-attempting-to-grant-privileges – Jim Buckley Barret May 01 '16 at 17:54

1 Answers1

1

check your connection string here

https://www.connectionstrings.com/mysql/

a standard way is

Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

some key are different from yours...

danilonet
  • 1,757
  • 16
  • 33