Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System.Windows.Forms;
  2. using MySql.Data.MySqlClient;
  3.  
  4. namespace SQLtry2
  5. {
  6. public partial class Form1 : Form
  7. {
  8. string serveraddress = "datasource=localhost;port=3306;username=root;password=jkd49Hzt";
  9. string commandstring = "SELECT * FROM tutschema.items";
  10. public Form1()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15. private void btn_connect_Click(object sender, EventArgs e)
  16. {
  17.  
  18.  
  19.  
  20. /* MySqlConnection myconnect = new MySqlConnection(serveraddress);
  21. myconnect.Open();
  22. MySqlCommand cmd = new MySqlCommand();
  23. cmd = cmd.Connection.CreateCommand();
  24. cmd.CommandText = "SELECT name FROM tutschema.items";
  25. MySqlDataReader reader = cmd.ExecuteReader();
  26. MessageBox.Show("Connected");*/
  27. MySqlConnection connection = new MySqlConnection(serveraddress);
  28. MySqlCommand command = new MySqlCommand();
  29. command.CommandText = commandstring;
  30. MySqlDataReader reader;
  31. connection.Open();
  32. reader = command.ExecuteReader();
  33. while (reader.Read())
  34. {
  35. string row = "";
  36. for(int i = 0; i<= reader.FieldCount; i++)
  37. {
  38. row += reader.GetValue(i).ToString() + ", ";
  39. Console.WriteLine(row);
  40. }
  41. connection.Close();
  42. }
  43. }
  44.  
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement