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.
-
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?Davide Piras– Davide Piras2012-01-25 17:17:13 +00:00Commented Jan 25, 2012 at 17:17
-
possible duplicate of Windows application using MySQL from a webserverjgauffin– jgauffin2012-01-25 20:02:52 +00:00Commented Jan 25, 2012 at 20:02
Add a comment
|
1 Answer
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();
1 Comment
BShakiba
I Found It Elsewhere But THANKS! Can You Do Me A Great Favour and answer my next problem Too?? :D