您的位置:首页 > 数据库

怎么在题目里添加图片到SQL数据库中

2008-04-08 09:44 239 查看



Public Class Form1Class Form1




Private db As New LzmTW.Data.SqlDatabase(".", "NorthWind")






Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim SqlCreate As String = "CREATE TABLE Simple(ID int , Photo image, sex bit)"


db.Execute(SqlCreate)


End Sub






Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Dim table As New DataTable("Simple")


db.Load("Simple", table, New String() {"ID"})


Me.DataGridView1.DataSource = table




If table.Rows.Count = 0 Then Return




Dim row As DataRow = table.Rows(0)


Dim bytes() As Byte = CType(row(1), Byte())




Dim m As New System.IO.MemoryStream(bytes)




Dim t As New System.Drawing.Bitmap(m)


Me.PictureBox1.Image = t


End Sub






Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click


Using d As New OpenFileDialog


With d


.Multiselect = False


.Filter = "*.PNG|*.PNG"


If .ShowDialog = Windows.Forms.DialogResult.OK Then


Using r As New System.IO.BinaryReader(System.IO.File.Open(.FileName, IO.FileMode.Open))


Dim len As Integer = CInt(New System.IO.FileInfo(.FileName).Length)


Dim bytes(len - 1) As Byte


r.Read(bytes, 0, len)




Dim m As New System.IO.MemoryStream(bytes)




Dim t As New System.Drawing.Bitmap(m)


Me.PictureBox1.Image = t




Dim row As DataRow = CType(Me.DataGridView1.DataSource, DataTable).NewRow


row(0) = CType(Me.DataGridView1.DataSource, DataTable).Rows.Count + 1


row(1) = bytes


row(2) = False


CType(Me.DataGridView1.DataSource, DataTable).Rows.Add(row)


End Using


End If


End With


End Using


End Sub








Private Sub Button4_Click()Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click


db.Update("Simple", CType(Me.DataGridView1.DataSource, DataTable), New String() {"ID"})


End Sub






Private Sub Button5_Click()Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click


db.Execute("DROP TABLE Simple")


End Sub




End Class

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: