Reputation: 13
I want to know the code which allows my C# Windows Application to use mysql database located on internet with C# in a windows application and run main queries such as delete, insert, select,etc. Please Explain like i am a newbie.
Upvotes: 1
Views: 8350
Reputation: 204766
Bind the MySQL .Net Connector in your project and then you can do something like:
using MySql.Data.MySqlClient;
string dbConnectionString = "SERVER=server_address;DATABASE=db_name;UID=user;PASSWORD=pass;";
MySqlConnection connection = new MySqlConnection(dbConnectionString);
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select name from mytable";
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
string name = "";
if (!Reader.IsDBNull(0))
name = (string)Reader["name"];
}
Reader.Close();
Upvotes: 2