上传软件并将其保存到数据库中 [英] upload software and save it into the database

查看:78
本文介绍了上传软件并将其保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用V.B上载软件和文档并将其保存在sql数据库中,并能够将其检索以下载下垂.请帮助,如果可能的话

how to upload softwares and documents using V.B and save it on sql database and be able to retrieve it for downloading purposis. please help if its possible

推荐答案

是的,有可能-FileUpload控件不在乎它上传的数据类型,尽管它通过了作为二进制流.您可以将其保存到SQL数据库的IMAGE或VARBINARY字段中(因为只有这些能够容纳8K字节以上的字节-在后一种情况下,将其定义为VARBINARY(MAX))
然后将它们保存到数据库中:
Yes, it''s possible - the FileUpload control doesn''t care what type of data it uploads, it just passes it though as a binary stream. You can save this to the IMAGE or VARBINARY field of an SQL database (since these are the only ones capable of holding more than 8K bytes - in the latter case define it as VARBINARY(MAX))
Then just save them to the database:
byte[] data = myFileUpload.FileBytes;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    SqlCommand com = new SqlCommand("INSERT INTO myTable (data) Values (@DT)", con);
    com.Parameters.AddWithValue("@DT", data);
    com.ExecuteNonQuery();
    }


这篇关于上传软件并将其保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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