How to store values in multiple table in single button click [Resolved]

Posted by Self-innovator under ASP.NET on 12/29/2011 | Points: 10 | Views : 4380 | Status : [Member] | Replies : 1
Hi pls provide me the solution
i've two txt boxes and 2 radiobuttonlist controls when i click on submit the values of 2 text box should store in ex:-txtTable and values of 2 radio controls should get store in ex:-radiotable...in a single button click event..

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Suvendu on: 12/29/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi !
If i got you correctly then I think you are asking, how store data to different tables at in a single event like a button click.
Although you can do it by a 2 different insert statements inside that event but, I suggest you to use a stored procedure.
Write 2 different insert statement for the 2 tables and keep all these in a single stored procedure. Now call that stored procedure on submit button click.
But if these datas are inter-dependent then you have to use transaction with exception handling.
If you are using SQL Server then your stored procedure should look like -

CREATE PROC [dbo].[spInstAllValues]

(
@txt1 NVARCHAR(100), --textbox1 value
@txt2 NVARCHAR(100), --textbox2 value
@rbtn1 NVARCHAR(100), --radiobtn1 value || if your field is nvarchar(100) in database
@rbtn2 NVARCHAR(100) --radiobtn2 value
)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO txtTable VALUES(@txt1,@txt2)

INSERT INTO radioTable VALUES(@rbtn1,@rbtn2)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
END


you can learn sql server transaction from following links-
http://www.sqlteam.com/article/introduction-to-transactions
http://www.codeproject.com/KB/database/sqlservertransactions.aspx

If I am missing something then plz reply..

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response