如何通过VB.NET在SQL Server数据库中存储和检索Excel文件 [英] How to store and retrieve file excel in sql server database through VB.NET
本文介绍了如何通过VB.NET在SQL Server数据库中存储和检索Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问您能帮我吗!
如何通过VB.NET在SQL Server数据库中存储和检索Excel文件
谢谢,
Bro can you help me, please!
How to store and retrieve file excel in sql server database through VB.NET
thanks,
推荐答案
图片:
表
Images:
Table
CREATE TABLE dbo.STORED_IMAGES
(
ID int NOT NULL IDENTITY (1, 1),
Img varbinary(MAX) NULL
)
储存影像:
Storing Image:
Dim CMD As New SqlClient.SqlCommand("insert into STORED_IMAGES(Img) values(@Img)",cn)
CMD.Parameters.Add("@Img", SqlDbType.VarBinary, Integer.MaxValue).Value = ReadFile(Path)
读取文件的功能:
Function for reading file:
Private Function ReadFile(sPath As String) As Byte()
Dim data As Byte() = Nothing
Dim fInfo As New IO.FileInfo(sPath)
Dim numBytes As Long = fInfo.Length
Using fStream As New IO.FileStream(sPath, IO.FileMode.Open, IO.FileAccess.Read)
Dim br As New IO.BinaryReader(fStream)
data = br.ReadBytes(CInt(numBytes))
End Using
Return data
End Function
从数据库获取:
Getting from DB:
Dim fcmd As New SqlCommand("select Img from STORED_IMAGES where ID=@ID", cn)
fcmd.Parameters.Add("@ID", SqlDbType.Int).Value = 3 'e.g.
Dim bytes As Byte() = fcmd.ExecuteScalar
参考:如何使用vb.net [使用SQL Server保存和检索图像 [
在SQL Server 2005中存储图像并进行检索来自VB.NET [ ^ ]
Excel文件:
使用vb.net检索存储在sql服务器中的excel文件 [ ^ ]
Ref: How to store and retrieve images in sql server database with vb.net[^]
Refer:
Save and retrieve images with SQL Server [^]
Storing images in SQL Server 2005 and retrieving them from VB.NET[^]
Excel Files:
Retrieve excel file stored in sql server using vb.net[^]
maddoxcom,
浏览此链接-
将文件存储在数据库中 [
Hi maddoxcom,
Go through this link-
Store file in database[^]
这篇关于如何通过VB.NET在SQL Server数据库中存储和检索Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文