Created
August 11, 2014 07:42
-
-
Save 0V/5d4f8c85c2513f7f5e21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MySql.Data.MySqlClient; | |
using System; | |
using System.Data; | |
namespace ConnectMysqlSample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string server = "localhost"; | |
string database = "sample_db"; | |
string user = "root"; | |
string pass = ""; | |
string myConnectionString = string.Format( | |
"Server={0};Database={1};Uid={2};Pwd={3}", | |
server, | |
database, | |
user, | |
pass); | |
using (var connection = new MySqlConnection(myConnectionString)) | |
{ | |
try | |
{ | |
connection.Open(); | |
var cmd = connection.CreateCommand(); | |
cmd.CommandText = "Select * From sample_table"; | |
var dataAdapter = new MySqlDataAdapter(cmd); | |
var dataSet = new DataSet(); | |
dataAdapter.Fill(dataSet); | |
Console.WriteLine(dataSet.GetXml()); | |
connection.Close(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Error : " + e.Message); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment