vb.net中将图片存入SQL Server 2000并能读出来使用

来源:互联网 发布:mysql in exists 性能 编辑:程序博客网 时间:2024/05/24 02:35

在数据库中建一个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 As String = "insert into Img values (@bytes) "Dim command As New SqlClient.SqlCommand(SQL, Connection)command.Parameters.Add("@bytes", SqlDBType.Binary).Value = Bytescommand.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.MemoryStreammStream.Write(Bytes, 0, Bytes.Length)mStream.Flush()Dim Img As New Bitmap(mStream)PictureBox1.Image = Img


0 0
原创粉丝点击