Visual Basic.NET - Almacenar Imagenes en Sqlite con vb.net

 
Vista:
sin imagen de perfil

Almacenar Imagenes en Sqlite con vb.net

Publicado por yorell (4 intervenciones) el 23/10/2015 02:47:06
Good Friends EXAMPLE someone will have a source of storing images in sqlite + Vb.net

Buen dia amigos alguien tendra un ejemplo fuente de insertar imagenes en una bd sqlite con vb.net

Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

Almacenar Imagenes en Sqlite con vb.net

Publicado por Marcelo (69 intervenciones) el 29/10/2015 07:40:53
Hey Yorell - Here's a pretty basic sample code to read and store image files into a sqlite database using VB .NET and System.Data.Sqlite. Have fun!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Imports System.Data.SQLite
Imports System.IO
 
Public Class Form1
    'Objeto Coneccion
    'La base de datos tiene por nombre AlmacenDeImagenes.sqlite
    'La DB tiene la siguiente estructura:
    'create table Imagenes(nombreImagen varchar(255) NOT NULL, dataImagen image Not NULL)
    Private mDB As New SQLiteConnection("data source=AlmacenDeImagenes.sqlite;version=3;")
    Private mOpenFile As System.Windows.Forms.OpenFileDialog
 
    'Evento Boton: btnImportar
    Private Sub btnImportar_Click(sender As Object, e As EventArgs) Handles btnImportar.Click
        mOpenFile = New System.Windows.Forms.OpenFileDialog
        'Tu puedes aceptar lo que se te de la gana...
        mOpenFile.Filter = "Jpg Files (*.jpg)|*.jpg|Jpeg Files (*.jpeg)|*.jpg|Png Files (*.png)|*.png"
        Dim Resultado As DialogResult = mOpenFile.ShowDialog()
        If Resultado = DialogResult.OK Then
            Dim fs As New IO.FileStream(mOpenFile.FileName, IO.FileMode.Open)
            Dim br As New IO.BinaryReader(fs)
            Dim byteArea As Byte() = br.ReadBytes(CInt(fs.Length))
            br.Close()
            Dim ms As New IO.MemoryStream(byteArea)
            ImportarImagen(mOpenFile.FileName, byteArea)
        Else
            MessageBox.Show("Operacion cancelada...")
        End If
 
    End Sub
 
    Private Sub ImportarImagen(ByVal mFileName As String, ByVal mData As Byte())
        Dim sSQL As String = "insert into Imagenes(nombreImagen, dataImagen) values(@FileName, @Data)"
        Using mCommand As New SQLiteCommand(sSQL, mDB)
            mCommand.Parameters.AddWithValue("@FileName", mFileName)
            mCommand.Parameters.AddWithValue("@Data", mData)
            mCommand.ExecuteNonQuery()
            MessageBox.Show("Ya esta!")
        End Using
 
    End Sub
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Abrir Base de Datos
        If mDB.State = ConnectionState.Closed Then
            mDB.Open()
        End If
    End Sub
End Class
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar