I am using the following line to store a string in database but am currently unable to store it as a single string. Every time it encounters a comma in the string it creates a new row in the database table.
cmd.Parameters.AddWithValue("@ImageURL", String.Join(",", img.ToArray()));
What is the way to go about it?
this is how i have defined the table:
@ImageURL VARCHAR(max)
AS
BEGIN
SET NOCOUNT ON added to prevent extra result sets from
interfering with SELECT statements.
SET NOCOUNT ON;
Insert statements for procedure here
insert into
DECLARE @String VARCHAR(100)
SET @String =''
IF(LEN(@Images)>0)
BEGIN
DELETE FROM Business_images WHERE BusinessId=@BusinessId
END
WHILE LEN(@ImageURL) > 0
BEGIN
SET @String = LEFT(@ImageURL, ISNULL(NULLIF(CHARINDEX(',', @ImageURL) - 1, -1), LEN(@ImageURL)))
SET @ImageURL = SUBSTRING(@ImageURL, ISNULL(NULLIF(CHARINDEX(',', @ImageURL), 0), LEN(@ImageURL)) + 1, LEN(@ImageURL))
insert into Images(ImageURL) values (@String)
END
END
FYI: I was able to insert into sql server. In my case
col1is of typenvarchar