Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySql.Data;
- using MySql.Data.MySqlClient;
- using System.IO;
- namespace feladat1127
- {
- class Program
- {
- public struct diak
- {
- public string azonosito, nev, telszam;
- }
- static public diak[] diakok = new diak[200];
- static public MySqlConnection conn = new MySqlConnection("server=localhost;user=root;database=tanulok;port=3306;password=");
- static public void adatbevitel1()
- {
- MySqlCommand query = new MySqlCommand
- ("insert into 10aosztaly(id,name,phone) values(122,'Jozsi',222)", conn);
- try
- {
- query.ExecuteNonQuery();
- Console.WriteLine("Record inserted successfull...");
- }
- catch (Exception)
- {
- Console.WriteLine("Query problem");
- }
- }
- static public void adatbevitel2()
- {
- string name, id, phone, q;
- Console.Write("id: ");
- id = Console.ReadLine();
- Console.Write("\nname: ");
- name = Console.ReadLine();
- Console.Write("\nphone: ");
- phone = Console.ReadLine();
- q = "insert into 10aosztaly(id,name,phone) values(" + id + ",'" + name + "'," + phone + ")";
- MySqlCommand query = new MySqlCommand(q, conn);
- try
- {
- query.ExecuteNonQuery();
- Console.WriteLine("Record inserted successfull...");
- }
- catch (Exception)
- {
- Console.WriteLine("Query problem");
- }
- }
- static public void adatbevitel3()
- {
- StreamReader sr = new StreamReader("igen.txt");
- int i, n;
- string q;
- string[] adottsor = new string[3];
- n = 0;
- do
- {
- adottsor = (sr.ReadLine()).Split(' ');
- diakok[n].azonosito = adottsor[0];
- diakok[n].nev = adottsor[1];
- diakok[n].telszam = adottsor[2];
- n++;
- } while (!sr.EndOfStream);
- sr.Close();
- for (i = 0; i < n; i++)
- {
- q = "insert into 10aosztaly(id,name,phone) values(" + diakok[i].azonosito + ",'" + diakok[i].nev + "'," + diakok[i].telszam + ")";
- MySqlCommand query = new MySqlCommand(q, conn);
- try
- {
- query.ExecuteNonQuery();
- Console.WriteLine("Record inserted successfull...");
- }
- catch (Exception)
- {
- Console.WriteLine("Query problem");
- }
- }
- }
- static public void lekerdezes1()
- {
- StreamWriter sw = new StreamWriter("tabladatok.txt");
- MySqlCommand query = new MySqlCommand("select * from 10aosztaly", conn);
- try
- {
- MySqlDataReader table = query.ExecuteReader();
- while (table.Read())
- {
- Console.WriteLine(table[0] + " " + table[1] + " " + table[2]);
- sw.WriteLine(table[0] + " " + table[1] + " " + table[2]);
- }
- table.Close();
- sw.Close();
- }
- catch (Exception)
- {
- Console.WriteLine("Query problem");
- }
- }
- static public void torles()
- {
- MySqlCommand query = new MySqlCommand("delete from 10aosztaly where id=10");
- try
- {
- query.ExecuteNonQuery();
- Console.WriteLine("Record deleted succesful!");
- }
- catch(Exception)
- {
- Console.WriteLine("Query problem!");
- }
- }
- static void Main(string[] args)
- {
- try
- {
- conn.Open();
- Console.WriteLine("Connection to tanulok database successfull!");
- //adatbevitel1();
- //adatbevitel2();
- //adatbevitel3();
- lekerdezes1();
- torles();
- }
- catch (Exception)
- {
- Console.WriteLine("Connection problem!");
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement