]> fbox.kageds.com Git - NEATEST.git/blob - NEA/AddGame.xaml.vb
Read/Write pictures to Games table
[NEATEST.git] / NEA / AddGame.xaml.vb
1 Imports System.Data
2 Imports System.Drawing
3 Imports System.IO
4 Imports Microsoft.Win32
5 Public Class AddGame
6 Dim cmd As New OleDb.OleDbCommand
7 Dim da3 As New OleDb.OleDbDataAdapter
8 Dim result As Integer
9 Dim imgpath As String
10 Dim arrImage() As Byte
11 Dim sql As String
12 Dim fileUri As Uri
13
14 Dim ds As New NEADataSet
15 Dim da As New NEADataSetTableAdapters.GamesTableAdapter
16 Dim dt As New NEADataSet.GamesDataTable
17
18
19 Private Sub Bntadd_Click(sender As Object, e As RoutedEventArgs) Handles bntadd.Click
20 Dim dr As NEADataSet.GamesRow
21
22
23 Try
24 Dim OFD As FileDialog = New OpenFileDialog()
25
26 OFD.Filter = "Image File (*.jpg;*.bmp;*.gif;*.png)|*.jpg;*.bmp;*.gif;*.png"
27
28 OFD.ShowDialog()
29
30 imgpath = OFD.FileName
31 fileUri = New Uri(OFD.FileName)
32
33
34
35 OFD = Nothing
36
37
38 Catch ex As Exception
39 MsgBox(ex.Message.ToString())
40 End Try
41
42 dr = dt.NewGamesRow()
43 dr.Item("Name") = "Hello"
44 If imgpath <> "" Then
45 Dim img As Image = Image.FromFile(imgpath)
46 Dim bArr As Byte() = imgToByteArray(img)
47 dr.Item("Icon") = bArr
48
49 End If
50 dt.AddGamesRow(dr)
51 da.Update(dt)
52 dt.Dispose()
53 da.Dispose()
54 End Sub
55 Private Function imgToByteArray(ByVal img As Image) As Byte()
56 Using mStream As New MemoryStream()
57 img.Save(mStream, Imaging.ImageFormat.Jpeg)
58 Return mStream.GetBuffer()
59 End Using
60 End Function
61
62 End Class