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.Windows.Forms;
- using System.Data.SqlClient;
- namespace Transakce
- {
- public partial class Form1 : Form
- {
- int text;
- int text2;
- public Form1()
- {
- InitializeComponent();
- }
- private string pripojovaci_retezec
- {
- get { return @"Data Source=.\SQLEXPRESS;Initial Catalog=Kadlec;User ID=sa;Password=OAznojmo123-"; }
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string prikaz1 = "DELETE FROM Zakaznici WHERE= @ID";
- string prikaz2 = "DELETE FROM Zakazky Where= @cizi_klic";
- SqlConnection pripojeni = new SqlConnection(pripojovaci_retezec);
- text = Convert.ToInt32(textBox1.Text);
- text2 = Convert.ToInt32(textBox2.Text);
- SqlCommand cmd1 = new SqlCommand(prikaz1, pripojeni);
- SqlCommand cmd2 = new SqlCommand(prikaz2, pripojeni);
- SqlTransaction transakce = null;
- try
- {
- pripojeni.Open();
- transakce = pripojeni.BeginTransaction();
- cmd1.Transaction = transakce;
- cmd2.Transaction = transakce;
- cmd1.ExecuteNonQuery();
- cmd2.ExecuteNonQuery();
- transakce.Commit();
- MessageBox.Show("Příkaz úspěšně vykonán");
- }
- catch
- {
- transakce.Rollback();
- MessageBox.Show("Transakce vrácena do původního stavu");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment