I'm going to design a web page for students parking permit application.I'm new to asp.net, I have a process in mind doing it like this:
The form asks student to choose a permit type, then fill in applicant info, like name, grade, vehicle info, student may have 2 vehicles, and payment method, check or credit card,
I plan to create 3 tables like tblPermit, tblapplicant, tblVehicle.
After the students fill in the form, click submit button, I pass the values and call a stored procedure, some thing like this.Dim CmdAsNew Data.SqlClient.SqlCommand(MySQL, MyConn)Cmd.CommandType = Data.CommandType.StoredProcedure
Then in the stored proceudre, I will do :
Begin
insert into Permit table, then get permitID, by using something like this:
Select @.PermitID=@.@.IdentityThen insert into Student table,then use
Select @.StudentID=@.@.Identity
Then insert into vehicle table.
All the above 3 processes I put it in begin, end--So that they will not messed up with other applicants data.
I think begin...end is one transaction.
SO am I doing correctly this way? Thanks
Begin...End doesn't signify a transaction, it signifies a code block. The idea is basically correct, but use SELECT @.PermitID=SCOPE_IDENTITY() instead. You should also wrap the whole thing in a transaction to be safe.
|||So shall I use something like this:
AS
Begin
Begin transaction
Set NoCount on
DECLARE @.PermitID INT
Insert table............
Commit Transaction
End
Can I use the begin transaction ...commit transaction in Begin ......end, or no need of begin..end.
Thanks
No comments:
Post a Comment