SqlDataSource - Insert to 2 tables problem.

S

ssims

I'm working with ASP.Net on IIS 5.1 and MSSQL 2000 and have a rather
frustrating problem. I'm trying to insert a record to a table, get the
identity value, and insert two additional records to a second table.
My insert command looks like this:

INSERT INTO TableA VALUES(PK_NameID, CQ1, CQ2, CQ3, CQ4);
DECLARE @ID int;
SET @ID = SCOPE_IDENTITY();
INSERT INTO TableB VALUES(@ID, IQ1, IQ2, IQ3, IQ4);
INSERT INTO TableB VALUES(@ID, IQ1, IQ2, IQ3, IQ4);

The insert command is all mashed together in the InsertCommand
parameter of a SqlDataSource. When I run the query by hand in sqlcmd,
everything works beautifully, but when I try to run it on the page,
only the first insert command is processed. I can't find any
information in any of the logs or anywhere on Google to suggest what is
going wrong. Any help is greatly appreciated.

Thanks,

-Sean
 
B

bpd

Try putting the command in a stored procedure and use the stored
procedure in your SQLDataSource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top