Connect to MySQL Database – Use Select, Insert, Update – C# C Sharp Visual Studio 2010

32
13



In this tutorial I show you how to connect to a mySQL database using C# and Visual Studio 2010. I also show you a few useful queries you can run: Select, Insert, and Update in order to use the data in the mySQL database.

WEBSITE:

FORUMS

FREE CODE SNIPPETS

Nguồn:https://wijstaanvooronzegrondrechten.org/

32 COMMENTS

  1. Can someone help me I am getting this message all the time "Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

    "

  2. Thanks for the video! Very helpful. Just want to give my two cents. I usually use dotConnect to access database applications https://www.devart.com/dotconnect/mysql/ and I am pretty satisfied with it. Have you tried it? Any comments on other vendors?

  3. I create a short playlist where I explain how to connect mysql with C#: https://www.youtube.com/watch?v=oeUxMn5DlH0
    I really appreciate every subscription.

  4. i created a sql server on my own pc. now i want a friend to be able to connect to it and get data from it. my line goes like this
    "server=localhost;userid=root;password=root;database=thebasement"

    but in localhost only i can connect right? and when i put my public ip in there, i cant and he cant connect.. how can i have it that all the guys that have my programm, can connect to my mysql server??

  5. i have a question like are there different ways to connect to mysql workbench to c#??? since i am using it or can it also work with php admin software as well??? plzzz answer me

  6. It seems like my code stops executing after conn.open(); If i Console.Writeline("something") before the conn.open(). it shows the string, if I CW something anywhere (in catch or in while(reader.Read())) it doesn't show anything. No exceptions are thrown.

    EDIT: You don't need to enter the port number if you're connecting with localhost

  7. You can go through the easy way and connect your MySQL database with C# application by means of new MySQL ODBC driver https://www.devart.com/odbc/mysql/download.html

    ODBC driver connection guide https://www.devart.com/odbc/mysql/docs/driver_configuration_and_conne.htm

  8. For anyone still wondering how to use with winforms
    i use xampp with phpmyadmin
    using MySql.Data.MySqlClient;
    namespace Project
    {
    public partial class Form1 : Form
    {
    //Veriables
    string connString = "Server=localhost;Uid=root;Database=mydatabase";
    public MySqlConnection conn;
           
    public Form1()
    {
    InitializeComponent();
    }
           
    //post username and password to database
    private void button1_Click(object sender, EventArgs e)
    {
    conn = new MySqlConnection(connString);
    {
    MySqlCommand SET = new MySqlCommand("Insert into users(username, password) values(@username, @password)", conn);
    SET.Parameters.AddWithValue("@username", textBox1.Text);
    SET.Parameters.AddWithValue("@password", textBox2.Text);
                   
     
    conn.Open();
    SET.ExecuteNonQuery();
    conn.Close();
    MySqlCommand GET = new MySqlCommand("Select id from users where username=@username", conn);
    }
    }
    // Update/edit username and password to database
    private void button2_Click(object sender, EventArgs e)
    {
    conn = new MySqlConnection(connString);
    {
    MySqlCommand SET = new MySqlCommand("Update users SET username=@username, password=@password WHERE id=@id AND username=@oldusername", conn);
    // you need to enter the old username & Id not very fancy but yeah
    // remove the @oldusername if you want
    SET.Parameters.AddWithValue("@oldusername", textBox6.Text);
    SET.Parameters.AddWithValue("@username", textBox5.Text);
    SET.Parameters.AddWithValue("@password", textBox7.Text);
    SET.Parameters.AddWithValue("@id", textBox3.Text);
    conn.Open();
    SET.ExecuteNonQuery();
    conn.Close();
    }
    }
    }
    }

  9. Gracias Amigo, llevo una materia llamada Redes Industriales…. el profe hizo una conexión con una base de datos……y no le entendi muy bien……pero a ti te entendi muy bien….gracias por el aporte….

    I'm learning English and I understood everything you said. 
    Thank so much

  10. I tried to Update my database but I had few problems with it. And now, after one hour of wasting time to find a solution, I came here and found out that I missed the basics 😀

    thanks

  11. Hi everyone! 
    Even if i installed the Mysql connector i didn't get the file : msql.data.dll !!
    May someone help me plzzz!
    And i have an application that must be done on windows forms, could this tutorial be applied on a winForm application?

    Thnx

LEAVE A REPLY

Please enter your comment!
Please enter your name here