TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sann Lin
NA
9
4.7k
Insert two tables in a time
Aug 28 2015 12:37 AM
I want to Insert 2 tables (which all have the same field) is Tbl_Branch &
Tbl_Branch
History at the same time.
But when the insert data is
Tbl_Branch
has 1 row and
Tbl_Branch
History
has 3 rows that 1 row has data and 2 rows are blank. Please see pictures
(
Tbl_Branch
)
Tbl_Branch
History
The following
is my code:
// Insert code
cmd = New SqlCommand("Branch", cnn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@name", txtBranchName.Text)
cmd.Parameters.AddWithValue("@location", txtLocation.Text)
cmd.Parameters.AddWithValue("@note", txtDescription.Text)
cmd.Parameters.AddWithValue("@inputby", txtUser.Text)
cmd.Parameters.AddWithValue("@inputdate", userDate)
cmd.ExecuteNonQuery()
// Stored Procedure
insert into Tbl_Branch(BranchName,Location,[Description], input_By, input_Date)
VALUES(@name,@location,@note,@inputby,@inputdate)
declare @lastrow int
select top 1 @lastrow = BranchId from Tbl_Branch
order by BranchId desc
DECLARE @insert INT
Select @insert = @@ROWCOUNT
if @insert>0
insert into Tbl_BranchHistory(BranchId,BranchName,Location,[description],status,update_By,update_Date)
VALUES(@lastrow,@name,@location,@note,@status,@updateby,@updatedate)
Reply
Answers (
2
)
Displaying gestures in XML!
Iam Getting duplicate values from stored procedure