Guest User

Untitled

a guest
May 28th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10.  
  11. namespace Transakce
  12. {
  13. public partial class Form1 : Form
  14. {
  15. int text;
  16. int text2;
  17.  
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private string pripojovaci_retezec
  24. {
  25. get { return @"Data Source=.\SQLEXPRESS;Initial Catalog=Kadlec;User ID=sa;Password=OAznojmo123-"; }
  26. }
  27.  
  28. private void Form1_Load(object sender, EventArgs e)
  29. {
  30.  
  31.  
  32. }
  33.  
  34. private void button1_Click(object sender, EventArgs e)
  35. {
  36. string prikaz1 = "DELETE FROM Zakaznici WHERE= @ID";
  37.  
  38. string prikaz2 = "DELETE FROM Zakazky Where= @cizi_klic";
  39.  
  40. SqlConnection pripojeni = new SqlConnection(pripojovaci_retezec);
  41.  
  42.  
  43. text = Convert.ToInt32(textBox1.Text);
  44. text2 = Convert.ToInt32(textBox2.Text);
  45.  
  46. SqlCommand cmd1 = new SqlCommand(prikaz1, pripojeni);
  47. SqlCommand cmd2 = new SqlCommand(prikaz2, pripojeni);
  48.  
  49.  
  50. SqlTransaction transakce = null;
  51.  
  52. try
  53. {
  54. pripojeni.Open();
  55.  
  56. transakce = pripojeni.BeginTransaction();
  57.  
  58. cmd1.Transaction = transakce;
  59. cmd2.Transaction = transakce;
  60.  
  61. cmd1.ExecuteNonQuery();
  62. cmd2.ExecuteNonQuery();
  63.  
  64. transakce.Commit();
  65.  
  66. MessageBox.Show("Příkaz úspěšně vykonán");
  67. }
  68. catch
  69. {
  70.  
  71. transakce.Rollback();
  72. MessageBox.Show("Transakce vrácena do původního stavu");
  73. }
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
  87. }
Add Comment
Please, Sign In to add comment