-1

how do i connect to Mysql database using c#?

i have this code

entstring MyConnection = "server=localhost; port=3306; databae=database_name; uid=root;pwd=;sslMode=None; ;
6
  • You can find thousands of guide for this. Please read stackoverflow.com/help/how-to-ask before asking. Commented Mar 17, 2017 at 10:19
  • Quite broad, you could use ODBC, OLEDB, MySQL .NET connector... Have you tried anything besides writting the connection string? Commented Mar 17, 2017 at 10:26
  • i was just trying to get my code out cause i struggled with it during my project...my connection wasnt working cause my sslMode wasn't indicated Commented Mar 17, 2017 at 10:34
  • 5
    Possible duplicate of How to connect to MySQL Database? Commented Mar 17, 2017 at 11:00
  • Possible duplicate of MySQL Connection String C# Commented Mar 17, 2017 at 11:19

2 Answers 2

1

First download MySql.Data package from nuget package manager then add namespace

//Add MySql Library
using MySql.Data.MySqlClient;

Connection Code-

string connString = "server=server;user=user;database=db;password=*****;";
MySqlConnection con = new MySqlConnection(connString);
Sign up to request clarification or add additional context in comments.

Comments

0

this is an idea .

string MyConnection = "server=localhost; port=3306; databae=database_name; uid=root;pwd=;sslMode=None; ;

string Query =  "INSERT INTO table_name(username,password)VALUES('"+textbox_name.Text+"','"+password_name.Password+"');
MySqlConnection con = new MySqlConnection(MyConnection);
MySqlCommand command = new MySqlCommand(Query,con);
con.open();
try{
command.ExcuteNonQuery();

}

    catch(Expection ex)

{

MessageDialog box = new MessageDialog(ex.ToString());
box.ShowAsync();

}

con.close();

}

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.