如何将“文件”作为二进制类型上载到现有SQL表中。 [英] How do I 'upload file' as binary type to an existing SQL table.

查看:102
本文介绍了如何将“文件”作为二进制类型上载到现有SQL表中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Basic 2017和VB的新手。我目前正在使用vb.net创建一个Web应用程序。我的问题是我正在尝试添加文件上传选项

我当前的应用程序。我希望能够将我的计算机中的任何文件类型保存为sql server中的二进制文件。我不熟悉正确处理二进制(或byte())。我正在尝试使用Fileupload控件。





我试过谷歌搜索。似乎没什么用。任何形式的帮助表示赞赏。



我尝试过:



旧版vb的代码示例

I am using Visual basic 2017 and quite a newbie to VB. I am currently creating a web application using vb.net . My problem is I am trying to add an file upload option to
my current application. I wanna be able to save any file type from my computer as a binary file in sql server. I am not familiar with handling binary (or byte() ) correctly. I am trying to use Fileupload control.


I've tried googling. Nothing seems to work. Any kind of help is appreciated.

What I have tried:

code samples for older versions of vb

推荐答案

只需通过参数化查询将数据作为字节数组传递:

Just pass the data as an array of bytes, via a parameterised query:
<pre>                Using con As New SqlConnection(strConnect)
                	con.Open()
                	Using com As New SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con)
                		com.Parameters.AddWithValue("@C1", myValueForColumn1)
                		com.Parameters.AddWithValue("@C2", myArrayOfData)
                		com.ExecuteNonQuery()
                	End Using
                End Using


这篇关于如何将“文件”作为二进制类型上载到现有SQL表中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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