Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I've one transaction on sql 2008,

SQL
 ALTER PROCEDURE SP_CAR_Purchase
	@IdBrand nchar (10), 
	@purchasecode nchar (15),
	@Date date,
	@IdPartner nchar (10),
	@NBPKB nchar (30),
	@Price Money, 
	@Discount Money,
	@IdType nchar (10), 
	@Npolisi nchar(10), 
	@Nchases nchar (30),
	@NMesin nchar (30),
	@Warna varchar (20), 
	@Tahun int, 
	@HBeli Money 
AS
	BEGIN TRANSACTION

	Insert into tbPurchase(Purchase_No,Pur_Date,Id_Partner,NBPKB)Values
	(@purchasecode, @Date, @IdPartner, @NBPKB) 

	Insert into tbRep_Purchase(Purchase_No,Total)Values(@purchasecode, @Price)

	Insert into tbSKKB (Type_No, NBPKB, NPolisi, Nchases, NMesin,   
        Color,Year,Pur_Price)
	Values (@IdType, @NBPKB, @Npolisi,@Nchases, @Nmesin,@Warna, @Tahun,@Price)

	if @@Error <> 0
		Begin
			Rollback Transaction
			End
	Else
		Begin
			Commit Transaction
	End


how to execute these transactions,
if I use vb.net programming language?
please help
Posted
Updated 13-May-11 18:35pm
v5
Comments
ZeeroC00l 14-May-11 0:36am    
--added 'pre' tag and tagged SQL2008 to the question

BR//
Harsha

1 solution

SqlConnection conn = new SqlConnection("Data Source = localhost; Initial Catalog = MobileShop; UID = sa; PWD = sa");
conn.Open();
SqlTransaction transaction = conn.BeginTransaction();
try
{
   SqlDataReader rdr = new SqlCommand("SELECT * FROM Category", conn, transaction).ExecuteReader();
   while (rdr.Read())
   {
      this.listBox1.Items.Add(rdr["Name"].ToString());
   }
   rdr.Close();
   new SqlCommand("INSERT INTO Category VALUES('W210i', g1,I love you)", conn, transaction).ExecuteNonQuery();
   //error and roll it back
   transaction.Commit();
   MessageBox.Show("Committed !");
}
catch
{
  transaction.Rollback();
  MessageBox.Show("Rolled back !");
}
finally
{
  conn.Close();
}
 
Share this answer
 
v2
Comments
pankajupadhyay29 14-May-11 1:38am    
Edited for readability extra line break removed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900