Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
SDC
Starting Member
3 Posts |
Posted - 2009-12-04 : 06:44:13
|
| I have two tables 1)stu_master 2)stu_detailsdesign are as follows.stu_master_____________s_id int primary key,s_name varchar(50)stu_details_________s_id int foreign key (with update and delete cascade)s_qly varcharI have a code in vb.net 2008 as followssub abc()try Dim tran As SqlTransaction = Nothing tran = con.BeginTransaction cmd = New SqlCommand("insert into stu_master VALUES(1,'ABC')",cmd,tran) cmd.ExecuteNonQuery()cmd = New SqlCommand("insert into stu_details values(1,'xyz')",cmd,tran) cmd.ExecuteNonQuery()tran.commitCatch ex As Exception If Not tran Is Nothing Then tran.Rollback() End If lbl_error.Text = ex.MessageEnd Try---------------------------------------Problem is that It's giving the foreign key reference error.I don't want to commit until the data in stu_details table is entered.But Until the transaction is commited the data is not shown in master table , giving the foreign key error.My question is that , "Is there any way to enter the data in both tables using a transaction if we have foreign key relationship"Please help. |
|
|
|
|
|