vb.net中将图片存入SQL Server 2000并能读出来使用
发布时间:2020-12-17 07:49:50 所属栏目:百科 来源:网络整理
导读:在数据库中建一个Img表,其中包含一个Img字段,类型为Image或Binary '将Bytes存入数据库Dim Stream As New IO.MemoryStreamPictureBox1.Image.Save(Stream,System.Drawing.Imaging.ImageFormat.Bmp)Stream.Flush()Dim Bytes As Byte() = Stream.ToArrayDim SQL
|
在数据库中建一个Img表,其中包含一个Img字段,类型为Image或Binary '将Bytes存入数据库
Dim Stream As New IO.MemoryStream
PictureBox1.Image.Save(Stream,System.Drawing.Imaging.ImageFormat.Bmp)
Stream.Flush()
Dim Bytes As Byte() = Stream.ToArray
Dim SQL As String = "insert into Img values (@bytes) "
Dim command As New SqlClient.SqlCommand(SQL,Connection)
command.Parameters.Add("@bytes",SqlDBType.Binary).Value = Bytes
command.ExecuteNonQuery
'读取
Dim Command As New SqlClient.SqlCommand(SQL,Connection)
Dim Reader As SqlClient.SqlDataReader = Command.ExecuteReader()
Dim Bytes as Byte()=Reader.Item("Img")
Dim mStream As New IO.MemoryStream
mStream.Write(Bytes,Bytes.Length)
mStream.Flush()
Dim Img As New Bitmap(mStream)
PictureBox1.Image = Img (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
