Advertisement
Guest User

Untitled

a guest
Apr 11th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using MySql.Data.MySqlClient;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace AutoKolcsonzoSzoftver
  13. {
  14. public partial class Foablak : Form
  15. {
  16. public Foablak()
  17. {
  18. InitializeComponent();
  19. Csatlakozas();
  20. }
  21.  
  22. private string server;
  23. private string database;
  24. private string uid;
  25. private string password;
  26. private MySqlConnection connection;
  27.  
  28. private MySqlDataAdapter mySqlDataAdapter;
  29.  
  30. void Csatlakozas()
  31. {
  32. {
  33. // TODO: This line of code loads data into the 'adatbazis1DataSet.tabla1' table. You can move, or remove it, as needed.
  34. server = "public ip címem (itt nem teszem közzé)";
  35. database = "autokolcsonzo";
  36. uid = "root";
  37. password = "admin1";
  38. string connectionString;
  39. connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
  40.  
  41. connection = new MySqlConnection(connectionString);
  42.  
  43. if (this.OpenConnection() == true)
  44. {
  45.  
  46.  
  47. //ÜgyfélTAB
  48. mySqlDataAdapter = new MySqlDataAdapter("select * from ugyfel", connection);
  49. DataSet DS = new DataSet();
  50. mySqlDataAdapter.Fill(DS);
  51. dataGridView1.DataSource = DS.Tables[0];
  52.  
  53. //AutókTAB
  54. mySqlDataAdapter = new MySqlDataAdapter("select * from autok", connection);
  55. DataSet DSauto = new DataSet();
  56. mySqlDataAdapter.Fill(DSauto);
  57. dataGridView2.DataSource = DSauto.Tables[0];
  58.  
  59. //MainTAB
  60. mySqlDataAdapter = new MySqlDataAdapter("select * from main", connection);
  61. DataSet DSmain = new DataSet();
  62. mySqlDataAdapter.Fill(DSmain);
  63. dataGridView3.DataSource = DSmain.Tables[0];
  64.  
  65.  
  66. //close connection
  67. this.CloseConnection();
  68. };
  69. }
  70.  
  71. }
  72.  
  73.  
  74. //Close connection
  75. private bool CloseConnection()
  76. {
  77. try
  78. {
  79. connection.Close();
  80. return true;
  81. }
  82. catch (MySqlException ex)
  83. {
  84. MessageBox.Show(ex.Message);
  85. return false;
  86. }
  87. }
  88.  
  89.  
  90.  
  91. private bool OpenConnection()
  92. {
  93. try
  94. {
  95. connection.Open();
  96. return true;
  97. }
  98. catch (MySqlException ex)
  99. {
  100. //When handling errors, you can your application's response based on the error number.
  101. //The two most common error numbers when connecting are as follows:
  102. //0: Cannot connect to server.
  103. //1045: Invalid user name and/or password.
  104. switch (ex.Number)
  105. {
  106. case 0:
  107. MessageBox.Show("Cannot connect to server. Contact administrator");
  108. break;
  109. case 1045:
  110. MessageBox.Show("Invalid username/password, please try again");
  111. break;
  112. default:
  113. MessageBox.Show(ex.Message);
  114. break;
  115. }
  116. return false;
  117. }
  118. }
  119.  
  120.  
  121.  
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement