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 System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace WindowsFormsApp2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- datagbehivs();
- }
- MySqlConnection csatlakozas = new MySqlConnection("datasource = localhost;port=3306;Initial Catalog='esemeny';username=root;password=");
- MySqlCommand parancs;
- private void datagbehivs()
- {
- string mysql = "SELECT*FROM napok";
- DataSet table = new DataSet();
- MySqlDataAdapter adapter = new MySqlDataAdapter(mysql, csatlakozas);
- adapter.Fill(table, "esemeny");
- dataGridView1.DataSource = table;
- dataGridView1.DataSource = table.Tables["esemeny"];
- }
- public void nyitvacsatlakozas()
- {
- if (csatlakozas.State == ConnectionState.Closed)
- {
- csatlakozas.Open();
- }
- }
- public void zarvacsatlakozas()
- {
- if (csatlakozas.State == ConnectionState.Open)
- {
- csatlakozas.Close();
- }
- }
- public void textbehivas(string query)
- {
- string mysql = ("SELECT*FROM napok");
- parancs = new MySqlCommand(mysql, csatlakozas);
- try
- {
- nyitvacsatlakozas();
- parancs = new MySqlCommand(query, csatlakozas);
- if (parancs.ExecuteNonQuery() == 1)
- {
- MessageBox.Show("sdsdssd");
- }
- else
- {
- MessageBox.Show("aaaaaaaaa");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- zarvacsatlakozas();
- }
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- datagbehivs();
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
- textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
- textBox3.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- string add =" INSERT INTO `napok`(`id`, `fname`, `lastname`) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
- textbehivas(add);
- datagbehivs();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement