Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I have created a store procedure to get update value in table if registration Nubmer is available in table. I'd code the following

SQL
CREATE PROC proc_UpdateOldBalance(@RegistrationNumber char(8), @BalanceAmount bigint)
as
    Declare @RowCount int
    SELECT @RowCount = COUNT(*) FROM OldBalance Where RegistrationNumber=@RegistrationNumber
    if (@rowCount<1)
        BEGIN
            PRINT 'You can not Update data. RegistrationNumber not available'
            ROLLBACK TRANSACTION
        END
    else
        update oldBalance set BalanceAmount = @BalanceAmount where RegistrationNumber=@RegistrationNumber
return



it is running fine on back-end But when I'm using this on front end it gives error.

code is as follow


VB
try
Dim mycom As SqlCommand = New SqlCommand("proc_UpdateOldBalance", ConnObj, transction)
            mycom.CommandType = CommandType.StoredProcedure

            mycom.Parameters.AddWithValue("@RegistrationNumber", txtRegistrationNo.Text)
            mycom.Parameters.AddWithValue("@BalanceAmount", txtBalanceRemain.Text)
            mycom.ExecuteNonQuery()

            transction.Commit()
        Catch sqlError As SqlException
            transction.Rollback()
            MessageBox.Show("Unable to deposit Fees" + System.Environment.NewLine + "Please contact Your Software Provider", "Payment Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
            MessageBox.Show(Convert.ToString(sqlError))
            Exit Sub
        End Try



it gives error when ExecuteNonQuery method calls. Kindly help me soon.
thanks
Posted
Updated 26-Apr-12 2:31am
v3
Comments
Nilesh Patil Kolhapur 26-Apr-12 0:36am    
what is error?
Prasad_Kulkarni 26-Apr-12 8:40am    
What error you're gettin??

I think there is transaction Error. Please remove transaction from front end and try it.
 
Share this answer
 
Comments
ShivKrSingh 26-Apr-12 5:18am    
I want to do this with transaction
Savalia Manoj M 26-Apr-12 9:34am    
Please give me your table definataion.
ShivKrSingh 26-Apr-12 10:39am    
it has only two colomn 'RegistrationNumber' 'BalanceAmount'.
actually in my case I want to insert data(payment) in One table and at the same time Want to update Remaining balance in oldbalance table. I want that either both statement commit or non. thats why I'm using transaction here. sql proc is running fine on back-end. But dont know how to use "sql proc" with trancsaction. there is coding mistake. but dont know what?
I've forgot to write

transction = ConnObj.BeginTransaction
 
Share this answer
 

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