我需要在没有参数的情况下将文件或字节保存在数据库中 [英] I need to save a file or bytes in a database WITHOUT parameters

查看:63
本文介绍了我需要在没有参数的情况下将文件或字节保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我已经在网上搜索了很多东西,但是还没有找到如何将文件(由用户提供)保存到SQL数据库中的方法.我需要在没有参数的情况下执行此操作,因为我们正在使用ASP.NET,因此它会使我们的应用程序减慢太多.

有人知道我该怎么做吗,还是有人链接到我可以得到我所需要的东西.

预先感谢,
丹尼尔·戈麦斯
波哥大哥伦比亚

Good Morning fellows, I''ve searched all over the web and I haven''t found how to save a file (given by the user) into a SQL database; I need to do it without paramaters because we''re working on ASP.NET so it will slow our application too much.

Does anyone know how I can do that or does anybody have a link where I can get what I need.

Thanks in advance,
Daniel Gomez
Bogota Colombia

推荐答案

我认为您可以使用类似的方法(但是我不太确定):

I think you can use something like this (but I''m not absolutely sure):

insert into blob_table(my_image) values(0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB);



0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB -它被图像转换为十六进制形式.



0xC9CBBBCCCEB9C8CABCCCCEB9C9CBBB - it is image converted to its hexadecimal form.


我假设不带参数执行",即不带命名参数执行"(即通过传递文字值).除了其他人的建议之外,还有一个主意...

您始终可以将二进制数据与字符串(例如,文本或varchar)相互转换.如果数据太大(例如varchar(8000))并且不能使用ntext,则始终可以拆分数据并进行多次调用以获取/设置数据的每个块.
I am assuming by "do it without parameters", you mean "do it without named parameters" (i.e., by passing the literal value). Aside from what the other person suggested, here is an idea...

You can always convert the binary data to and from a string (e.g., text or varchar). If the data is too large for, say, a varchar(8000) and you can''t use ntext, you can always split the data and make multiple calls to get/set each chunk of it.


您的意思是,您得到十六进制形式".那只是表示二进制数据的一种方式,但实际上,它仍然只是二进制数据.文件也只存储二进制数据.通常,二进制数据在VB.Net和C#中表示为字节数组.也许您应该使用一些代码来更新您的问题,这些代码演示您在转换数据类型时遇到的问题.
What do you mean, you get the "hexadecimal form". That''s just one way you represent binary data, but under the hood it''s still just binary data. Files also just store binary data. Usually that binary data is represented in VB.Net and C# as an array of bytes. Perhaps you should update your question with some code that demonstrates the problem you''re having with converting the data types.


这篇关于我需要在没有参数的情况下将文件或字节保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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