I need to create a ticket with its details. From visual studio I send a string list or string array to sql with the data to create the ticket. The amount of details is variable, my question is how to execute that x amount of details in sql server.
I am using visual studio 2017 and sql server 2008.
GO
create procedure newTicketWithDetails
@idProduct int,
as
BEGIN TRANSACTION
BEGIN TRY
/*
idTicket is identity
idTicket and dateTicket are PK
*/
insert into Tickets(idTicket,dateTicket))
values (GETDATE());
insert into TicketsDetails(idTicket,dateTicket,idProduct)
values(IDENT_CURRENT('Tickets'),GETDATE(),@idProduct);
/*
...
... x inserts here
...
*/
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SELECT @@ROWCOUNT
END CATCH
Something like that is what I am trying to do. How should I go through that array with ticket data or how should I send the details from visual studio?