Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using MySql.Data.MySqlClient;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace AutoKolcsonzoSzoftver
- {
- public partial class Foablak : Form
- {
- public Foablak()
- {
- InitializeComponent();
- Csatlakozas();
- }
- private string server;
- private string database;
- private string uid;
- private string password;
- private MySqlConnection connection;
- private MySqlDataAdapter mySqlDataAdapter;
- void Csatlakozas()
- {
- {
- // TODO: This line of code loads data into the 'adatbazis1DataSet.tabla1' table. You can move, or remove it, as needed.
- server = "public ip címem (itt nem teszem közzé)";
- database = "autokolcsonzo";
- uid = "root";
- password = "admin1";
- string connectionString;
- connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
- connection = new MySqlConnection(connectionString);
- if (this.OpenConnection() == true)
- {
- //ÜgyfélTAB
- mySqlDataAdapter = new MySqlDataAdapter("select * from ugyfel", connection);
- DataSet DS = new DataSet();
- mySqlDataAdapter.Fill(DS);
- dataGridView1.DataSource = DS.Tables[0];
- //AutókTAB
- mySqlDataAdapter = new MySqlDataAdapter("select * from autok", connection);
- DataSet DSauto = new DataSet();
- mySqlDataAdapter.Fill(DSauto);
- dataGridView2.DataSource = DSauto.Tables[0];
- //MainTAB
- mySqlDataAdapter = new MySqlDataAdapter("select * from main", connection);
- DataSet DSmain = new DataSet();
- mySqlDataAdapter.Fill(DSmain);
- dataGridView3.DataSource = DSmain.Tables[0];
- //close connection
- this.CloseConnection();
- };
- }
- }
- //Close connection
- private bool CloseConnection()
- {
- try
- {
- connection.Close();
- return true;
- }
- catch (MySqlException ex)
- {
- MessageBox.Show(ex.Message);
- return false;
- }
- }
- private bool OpenConnection()
- {
- try
- {
- connection.Open();
- return true;
- }
- catch (MySqlException ex)
- {
- //When handling errors, you can your application's response based on the error number.
- //The two most common error numbers when connecting are as follows:
- //0: Cannot connect to server.
- //1045: Invalid user name and/or password.
- switch (ex.Number)
- {
- case 0:
- MessageBox.Show("Cannot connect to server. Contact administrator");
- break;
- case 1045:
- MessageBox.Show("Invalid username/password, please try again");
- break;
- default:
- MessageBox.Show(ex.Message);
- break;
- }
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement