构建INSERT语句错误的Https已经声明 [英] build insert statement error Https has already been declared

查看:146
本文介绍了构建INSERT语句错误的Https已经声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从UI获取多个图像并且将它们存储在高速缓存中的方法,当该已完成它调用一个方法,该方法然后引用缓存拉图像出来,然后将它们传送到数据库,此刻本INSERT语句目前正在做一下午时间,因此它可能是7命中数据库中的用户。

我正在绑实现是这样的,在SQL你会做

(插入到数据库中一次多个项目)

 插入表1(第一,最后)

     (弗雷德,史密斯),
     (约翰,史密斯),
     (迈克尔,史密斯),
     ('罗伯特','史密斯);

我的code目前看起来像这样

 公共无效SaveImages(列表<图像及GT;图片,Int64的用户id)
{
  VAR延长= Images.Aggregate(的String.Empty,(目前,项目)= GT;当前+的String.Format(({0},{1},{2},{3},{4},{5} ),用户id,item.ImageName,item.ImageUrl,1,DateTime.Now,NULL));
}

曾经完成的扩展看起来像这样

<$p$p><$c$c>(1253,xkvkvy4ldmfbhlmftqsc,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309462/rfefef.jpg,1,07/02/2015十一时45分29秒,),
(1253,pa0niomwvyzl47qjlxna,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309471/iuytre.jpg,1,07/02/2015十一时45分29秒,),
(1253,mymvektwddgco9nvbaap,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309479/sdfgh.jpg,1,07/02/2015十一时45分29秒,),
(1253,fxlftcx9jgrs9c7sjnv4,https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309489/98iuiu.jpg,1,07/02/2015十一时45分29秒,),

和我所说的INSERT语句,并通过在扩展

  VAR的查询= @
           INSERT INTO [用户] .Images
                  (用户ID,文件名,的ImageUrl,活动,CreatedDate,DeletedDate)            VALUES
                  +扩展名;sqlCon.Query(查询);

但以下原因失败,因为

 标签的https已声明。标签名称必须是查询批处理或存储过程中是唯一的。

我GOOGLE了这个错误,但我并没有因此受到什么好的解决办法,为什么我问这里。


解决方案

尝试把URL(和其他字符串值)引号之间:

<$p$p><$c$c>(1253,'xkvkvy4ldmfbhlmftqsc','https://res.cloudinary.com/dncu6pqpm/image/upload/v1423309462/rfefef.jpg',1,07/02/2015十一时45分29秒,)

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.

解决方案

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,)

这篇关于构建INSERT语句错误的Https已经声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆