Insert Into Multiple values table using stored procedure and DataAccessLayer [duplicate]


Insert Into Multiple values table using stored procedure and DataAccessLayer [duplicate]



This question already has an answer here:



I am trying making a test on how to add multiple values into a column, which accepts multiple values.



For example, I have two tables


Table 1: contains `ID` (`int`) primary, `Name` (`varchar`)
Table 2: contains `ID` (reference to Table 1's `ID`), `Image` (`image`)



I created these tables, and I can insert data into table one, but how can I let it insert into multiple value column in table 2 (Image)?


Image



I can have Id and add images how much I want, I tried with stored procedure, using insert, but failed, because I want to check ID is the same to ID in table 1 using where statement not working in insert



For more examples.


ID: 1, Name: Willam, Image:[AnyImage] (More than 1 image)
ID: 2, Name: Edi, Image[Anyknownimage], Image[AnyNewImage] etc...



Anything that helps?



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





Tag properly!!! MySQL <> SQL Server. Which one is this????
– Eric
2 days ago





Not Identity, it's about insert multiple values in same table
– Samer Yousef
2 days ago





Why do you have Image in both tables? Image should not be in the 1st table.
– jdweng
2 days ago





Alright, I changed it.
– Samer Yousef
2 days ago





The image data types will be removed in a future version of SQL Server. Avoid using this data type in new development work, and plan to modify applications that currently use it. Use varbinary(max) instead. See details here
– marc_s
2 days ago


image


varbinary(max)




1 Answer
1



I think I've found a solution to my Question.
The way I should do is to Set Identity_insert to on before insert and turn it off after insert in a procedure.
Before the Set insert.


CREATE proc [dbo].[Add_Image]
@ID int,
@Image image
as
Insert into ImageContainer(ID,Image) values(@ID,@Image)



After the altering the table to:


CREATE proc [dbo].[Add_Image]
@ID int,
@Image image
as
SET IDENTITY_INSERT ImageContainer ON
Insert into ImageContainer(ID,Image) values(@ID,@Image)
SET IDENTITY_INSERT ImageContainer off



Thanks to you all

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift