build insert statement error Https has already been declared

不羁的心 提交于 2019-12-12 05:25:54

问题


I have a method which takes multiple images from the UI and stores them in the cache, when this has finished it calls a method which then references the cache pulls the images out and then passes them to the database, at the moment this insert statement is currently doing one at time, so it could be 7 hits to the database for one user.

What I'm tying to achieve is something like this, in SQL you would do (multiple items inserted in to the database at once)

insert into table1 (First,Last) 
values 
     ('Fred','Smith'),
     ('John','Smith'),
     ('Michael','Smith'),
     ('Robert','Smith');

my code currently looks like this

public void SaveImages(List<Images> Images, Int64 userId)
{
  var extension = Images.Aggregate(string.Empty, (current, item) => current + string.Format("({0},{1},{2},{3},{4},{5}),", userId, item.ImageName, item.ImageUrl, 1, DateTime.Now, null));
}

which once finished extension looks like this

(1253,xkvkvy4ldmfbhlmftqsc,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309462/rfefef.jpg,1,07/02/2015 11:45:29,),
(1253,pa0niomwvyzl47qjlxna,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309471/iuytre.jpg,1,07/02/2015 11:45:29,),
(1253,mymvektwddgco9nvbaap,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309479/sdfgh.jpg,1,07/02/2015 11:45:29,),
(1253,fxlftcx9jgrs9c7sjnv4,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309489/98iuiu.jpg,1,07/02/2015 11:45:29,),

And I call the insert statement and pass in extension

var query = @"
           INSERT INTO [User].Images
                  (UserId, FileName, ImageUrl, Active, CreatedDate, DeletedDate)

            VALUES
                  " + extension;

sqlCon.Query(query);

but it fails due to the following reason

The label 'https' has already been declared. Label names must be unique within a query batch or stored procedure.

I have googled this error, but I didn't receive any good solutions hence why I am asking here.


回答1:


Try putting the url (and other string values) between quotes:

(1253,'xkvkvy4ldmfbhlmftqsc','https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309462/rfefef.jpg',1,07/02/2015 11:45:29,)


来源:https://stackoverflow.com/questions/28381982/build-insert-statement-error-https-has-already-been-declared

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!