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.MySqlClient;
- namespace ConsoleApplication8
- {
- class Program
- {
- static void Main(string[] args)
- {
- ////Uvod///
- Console.WriteLine("***********************************************************************");
- Console.WriteLine("*** Zadaj MySql udaje oddelene dvojbodkou ***");
- Console.WriteLine("*** MYSERVER:MYDATABASE:MYTABLE(TXT):MYTABLE(INT):MYUSER:MYPASS ***");
- Console.WriteLine("***********************************************************************");
- string[] zadane = Console.ReadLine().Split(':');
- string srvr=zadane[0], dtbs=zadane[1], tbl=zadane[2],tbl2=zadane[3],usr=zadane[4], pas=zadane[5];
- ////Zadávač///
- Console.WriteLine("Napis text alebo cislo ktore chces pridat do MYSQL:");
- string cislotext = Console.ReadLine();
- ////MYSQL PRIPOJENIE///
- string udaje= (@"server=" + srvr + ";database=" + dtbs + ";userid=" + usr + ";password=" + pas);
- try
- {
- using (MySqlConnection connect = new MySqlConnection(udaje))
- {
- connect.Open();
- int x;
- if (int.TryParse(cislotext, out x))
- {
- using (MySqlCommand cmnd = new MySqlCommand("INSERT INTO " + tbl2 + " (cislo) VALUES (@cislo)"))
- {
- cmnd.Parameters.Add("@cislo", cislotext);
- cmnd.ExecuteNonQuery();
- }
- }
- else
- {
- using (MySqlCommand cmndd = new MySqlCommand("INSERT INTO " + tbl + " (text) VALUES (@text)"))
- {
- cmndd.Parameters.Add("@text", cislotext);
- cmndd.ExecuteNonQuery();
- }
- }
- connect.Close();
- }
- }
- catch (System.Exception excep)
- {
- Console.WriteLine(excep.Message);
- }
- Console.Beep();
- Console.WriteLine("Úspešne pridane do DB ;D ");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement