我正在使用以下行将字符串存储在数据库中,但目前无法将其存储为单个字符串。每次在字符串中遇到逗号时,它都会在数据库表中创建一个新行。
cmd.Parameters.AddWithValue("@ImageURL", String.Join(",", img.ToArray()));
有什么办法呢?
这就是我定义表格的方式:
@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