Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- string[] users = GetMySqlResults("SELECT users FROM myTable");
- }
- static string[] GetMySqlResults(string query) {
- string[] results = new string[]{};
- try
- {
- using(MySqlConnection con = new MySqlConnection("server=localhost;user=username;password=12345;database=mydb"))
- {
- con.Open();
- using(MySqlCommand cmd = new MySqlCommand(query, con))
- {
- using(MySqlDataReader reader = cmd.ExecuteReader())
- {
- results = new string[reader.FieldCount];
- for(int i = 0; i < results.Length; i++)
- {
- results[i] = reader[i].ToString();
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement