VB.NET和MS SQL FileStream [英] VB.NET and MS SQL FileStream

查看:57
本文介绍了VB.NET和MS SQL FileStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Exe转换为byte并将其插入Filestream数据库。然后检索它并将其转换回Exe?如果它是可能的。你能告诉我怎么样吗?谢谢!

Is it possible to convert an Exe into byte and Insert it in a Filestream database. Then retrieve it and convert it back to an Exe? If its possible. Can you please teach me how. Thank you!

推荐答案

非常感谢先生,我已经测试了它,我可以在我的数据库中插入字节数组。最后一个问题,如何将字节数组转换为Exe并将其保存到文件路径?谢谢你,先生!最好的问候!
Thanks a lot sir, I''ve tested it and I can insert the byte array in my database. One last question, how can I convert the byte array into Exe and save it to a file path? Thank you sir! Best regards!


EXE文件是一个字节流,没有别的。当您告诉它运行该文件时,系统会将这些字节解释为可执行程序。所以是的,如果需要,可以将它存储在数据库中 - 只需将其作为字节数组(使用File.ReadAllBytes)读取,并以与图像相同的方式将其保存到数据库中 - 通过参数化查询。 />
An EXE file is a stream of bytes and nothing else. The system interprets those bytes as an executable program when you tell it to run the file. So yes, you can store it in a database if you need to - just read it as a byte array (using File.ReadAllBytes) and save it into the database in the same way you would an image - via a parameterized query.
Dim data As Byte() = File.ReadAllBytes("D:\Temp\MyApp.exe")
Using con As New SqlConnection(strConnect)
    con.Open()
    Using com As New SqlCommand("INSERT INTO myTable (myExeColumn) VALUES (@EXE)", con)
        com.Parameters.AddWithValue("@EXE", data)
        com.ExecuteNonQuery()
    End Using
End Using

< br $> b $ b





非常感谢先生,我已经测试了,我可以插入我的数据库中的字节数组。最后一个问题,如何将字节数组转换为Exe并将其保存到文件路径?谢谢你,先生!最好的问候!







"Thanks a lot sir, I''ve tested it and I can insert the byte array in my database. One last question, how can I convert the byte array into Exe and save it to a file path? Thank you sir! Best regards!"

Using con As New SqlConnection(strConnect)
	con.Open()
	Using com As New SqlCommand("SELECT myExeColumn FROM myTable WHERE id=@ID", con)
		com.Parameters.AddWithValue("@ID", idOfMyEXEFileRow)
		Using reader As SqlDataReader = com.ExecuteReader()
			While reader.Read()
				Dim data As Byte() = DirectCast(reader("myExeColumn"), Byte())
				File.WriteAllBytes("D:\Temp\myApp.exe", data)
			End While
		End Using
	End Using
End Using


这篇关于VB.NET和MS SQL FileStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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