1

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.

2
  • how do you access your mySQL, via IP address? is that your server or your hosting provider server? are you sure the provider allows you to connect to it remotely and not only from a hosted web application? Commented Jan 25, 2012 at 17:17
  • possible duplicate of Windows application using MySQL from a webserver Commented Jan 25, 2012 at 20:02

1 Answer 1

2

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();
Sign up to request clarification or add additional context in comments.

1 Comment

I Found It Elsewhere But THANKS! Can You Do Me A Great Favour and answer my next problem Too?? :D

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.