Public
Class Form1
Class 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
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