Advertisement
SC0U7

Untitled

Aug 22nd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7.  
  8.  
  9.  
  10.  
  11. namespace ConsoleApplication8
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             ////Uvod///
  18.             Console.WriteLine("***********************************************************************");
  19.             Console.WriteLine("***            Zadaj MySql udaje oddelene dvojbodkou                ***");
  20.             Console.WriteLine("***   MYSERVER:MYDATABASE:MYTABLE(TXT):MYTABLE(INT):MYUSER:MYPASS   ***");
  21.             Console.WriteLine("***********************************************************************");
  22.             string[] zadane = Console.ReadLine().Split(':');
  23.             string srvr=zadane[0], dtbs=zadane[1], tbl=zadane[2],tbl2=zadane[3],usr=zadane[4], pas=zadane[5];
  24.              ////Zadávač///
  25.             Console.WriteLine("Napis text alebo cislo ktore chces pridat do MYSQL:");
  26.             string cislotext = Console.ReadLine();
  27.             ////MYSQL PRIPOJENIE///
  28.             string udaje= (@"server=" + srvr + ";database=" + dtbs + ";userid=" + usr + ";password=" + pas);
  29.             try
  30.             {
  31.                 using (MySqlConnection connect = new MySqlConnection(udaje))
  32.                 {
  33.                     connect.Open();
  34.  
  35.  
  36.                     int x;
  37.                     if (int.TryParse(cislotext, out x))
  38.                     {
  39.  
  40.                         using (MySqlCommand cmnd = new MySqlCommand("INSERT INTO " + tbl2 + " (cislo) VALUES (@cislo)"))
  41.                         {
  42.  
  43.                             cmnd.Parameters.Add("@cislo", cislotext);
  44.                             cmnd.ExecuteNonQuery();
  45.                         }
  46.                     }
  47.                     else
  48.                     {
  49.                         using (MySqlCommand cmndd = new MySqlCommand("INSERT INTO " + tbl + " (text) VALUES (@text)"))
  50.                         {
  51.  
  52.                             cmndd.Parameters.Add("@text", cislotext);
  53.                             cmndd.ExecuteNonQuery();
  54.  
  55.                         }
  56.                     }
  57.  
  58.  
  59.                     connect.Close();
  60.                 }
  61.             }
  62.             catch (System.Exception excep)
  63.             {
  64.  
  65.                 Console.WriteLine(excep.Message);
  66.  
  67.             }
  68.             Console.Beep();
  69.             Console.WriteLine("Úspešne pridane do DB ;D ");
  70.             Console.ReadKey();
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement