16,718
社区成员
发帖
与我相关
我的任务
分享
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DA = New SqlDataAdapter("select * from employees", cnn)
DA.Fill(DS)
'从数据库加载图片
'内存流
Dim BT() As Byte '字节数组
BT = DS.Tables(0).Rows(0).Item("Photo") '从数据库中读出的OLE对象
Dim MS As New MemoryStream(BT, 78, BT.Length - 78)
PictureBox1.Image = Image.FromStream(MS)
'Dim myfilestream As New System.IO.FileStream(Application.StartupPath & "\monkey.bmp", IO.FileMode.Create)
'myfilestream.Write(BT, 80, BT.Length - 1)
'myfilestream.Close()
'PictureBox1.Image = Image.FromFile(Application.StartupPath & "\monkey.bmp")
End Sub
Public Class Form1
Private db As New Global.LzmTW.Data.SqlSqlClientDatabase(".", "Northwind")
Private WithEvents binding As New BindingSource
Private Const position As Integer = 4 * 16 + 14
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.DataSource = binding
binding.DataSource = db.GetDataTable("Employees")
End Sub
Private Sub binding_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles binding.PositionChanged
Dim bytes As Byte() = CType(CType(binding.Current, DataRowView).Row.Item("Photo"), Byte())
Dim stream As New IO.MemoryStream(bytes, position, bytes.Length - position)
Dim bitmap As New System.Drawing.Bitmap(stream)
Me.PictureBox1.Image = bitmap
End Sub
End Class
FS = New FileStream(mFileInfo.FullName, FileMode.Open, FileAccess.Read)
ReDim BT(FS.Length)
FS.Read(BT, 0, FS.Length - 1) '关键就是这里
FS.Close()
FS = Nothing
SqlConn.InsertPic(tbXmName.Text, cbType.Text, cbSubType.Text, BT)
BT = Nothing
'记录成功个数
intInTotal += 1
FS.Read(BT, 0, FS.Length) '把那个-1去掉,就可以了,多读取一个字节