如何将文件作为varchar插入sqlserver2008 [英] how to insert files as varchar into sqlserver2008

查看:87
本文介绍了如何将文件作为varchar插入sqlserver2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将任何文件(如word或pdf ....)作为varchar插入sqlserver.


如何在varchar中插入文件

请帮助我


我使用了这段代码,但是没有用

Hi,

I want to insert any file like word or pdf.... as varchar into sqlserver.


how to insert file in varchar

please help me


i used this code but it hasn''t worked

if (FileUpload1.FileName != "")
       {
           string filePath = Server.MapPath("~/pp/") + FileUpload1.FileName;
           string ext = Path.GetExtension(FileUpload1.FileName);

           switch (ext)
           {
               case ".doc":
                   contenttype = "application/vnd.ms-word";
                   break;

               case ".docx":
                   contenttype = "application/vnd.ms-word";
                   break;
           }
           FileUpload1.SaveAs(filePath);
           StreamReader myFile = new System.IO.StreamReader(filePath);
           myString = myFile.ReadToEnd();

           myFile.Close();





但它正在插入,就像在我的数据库中一样:-


????





but it is inserting as in my database:-


????

推荐答案

Varchar用于字符数据,而不用于文件字节,为此,您必须使用varbinary.

参见此处: http://www.daniweb.com/software-development/csharp/code/217419 [ ^ ]
Varchar is for character data not for file bytes, for this you must use varbinary instead.

See here : http://www.daniweb.com/software-development/csharp/code/217419[^]


尝试使用varbinary而不是varchar. varbinary帮助您保存文件的内容.
--NDK
try to use varbinary instead of varchar. varbinary helps you to save the content of the file.
--NDK


varchar适用于文本/字符串,不适用于文件数据类型:)
varchar is for text/strings and not for file data types :)


这篇关于如何将文件作为varchar插入sqlserver2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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