Click here to Skip to main content
15,907,183 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: how to put a time counter in my vb.net project? Pin
Rharzkie9-Mar-08 23:00
Rharzkie9-Mar-08 23:00 
GeneralRe: how to put a time counter in my vb.net project? Pin
Guffa9-Mar-08 23:05
Guffa9-Mar-08 23:05 
GeneralRe: how to put a time counter in my vb.net project? Pin
Rharzkie9-Mar-08 23:31
Rharzkie9-Mar-08 23:31 
Questionhelp. to include flash in vb.net form? Pin
jomet9-Mar-08 17:29
jomet9-Mar-08 17:29 
AnswerRe: help. to include flash in vb.net form? Pin
C1AllenS9-Mar-08 19:02
C1AllenS9-Mar-08 19:02 
GeneralRe: help. to include flash in vb.net form? Pin
jomet9-Mar-08 21:55
jomet9-Mar-08 21:55 
GeneralRe: help. to include flash in vb.net form? Pin
jomet9-Mar-08 22:02
jomet9-Mar-08 22:02 
Generalstoring images into DB Pin
Aamir Mustafa9-Mar-08 2:30
Aamir Mustafa9-Mar-08 2:30 
i want to save image in db
i m using ms access db
images are stored in database successfully.
i have added a list box on the form and i want that when i save image in db so that image name should be added in list box
but i don't know how to do that

i m also giving code below
any body can help me.
thanks


Option Strict On
Imports System.Data.SqlClient
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form
Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Replace(Application.StartupPath, "bin", "") & "DB.mdb;Mode=ReadWrite;Persist Security Info=False")

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents PicBindingSource As System.Windows.Forms.BindingSource
Friend WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Friend WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents DataSet11 As LoadinImages.DataSet1

<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.Label1 = New System.Windows.Forms.Label
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.DataSet11 = New LoadinImages.DataSet1
Me.PicBindingSource = New System.Windows.Forms.BindingSource(Me.components)
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
Me.TextBox1 = New System.Windows.Forms.TextBox
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PicBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.ForeColor = System.Drawing.Color.Black
Me.Button1.Location = New System.Drawing.Point(121, 376)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Browse"
'
'Button2
'
Me.Button2.ForeColor = System.Drawing.Color.Black
Me.Button2.Location = New System.Drawing.Point(220, 377)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Save"
'
'PictureBox1
'
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(24, 16)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(301, 304)
Me.PictureBox1.TabIndex = 3
Me.PictureBox1.TabStop = False
'
'Label1
'
Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Label1.ForeColor = System.Drawing.Color.Red
Me.Label1.Location = New System.Drawing.Point(24, 341)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(427, 32)
Me.Label1.TabIndex = 4
'
'ListBox1
'
Me.ListBox1.BackColor = System.Drawing.SystemColors.Control
Me.ListBox1.HorizontalScrollbar = True
Me.ListBox1.Location = New System.Drawing.Point(331, 16)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.ScrollAlwaysVisible = True
Me.ListBox1.Size = New System.Drawing.Size(120, 303)
Me.ListBox1.TabIndex = 7
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
Me.DataSet11.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
'
'PicBindingSource
'
Me.PicBindingSource.DataMember = "Pic"
Me.PicBindingSource.DataSource = Me.DataSet11
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = resources.GetString("OleDbConnection1.ConnectionString")
'
'OleDbDataAdapter1
'
Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "Images", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Filename", "Filename"), New System.Data.Common.DataColumnMapping("Photo", "Photo")})})
'
'OleDbInsertCommand1
'
Me.OleDbInsertCommand1.CommandText = "INSERT INTO Images(Filename, Photo) VALUES (?, ?)"
Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
Me.OleDbInsertCommand1.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() {New System.Data.OleDb.OleDbParameter("Filename", System.Data.OleDb.OleDbType.VarWChar, 50, "Filename"), New System.Data.OleDb.OleDbParameter("Photo", System.Data.OleDb.OleDbType.VarBinary, 0, "Photo")})
'
'OleDbSelectCommand1
'
Me.OleDbSelectCommand1.CommandText = "SELECT Filename, Photo FROM Images"
Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(124, 406)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(171, 20)
Me.TextBox1.TabIndex = 8
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(466, 438)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.ForeColor = System.Drawing.Color.White
Me.Name = "Form1"
Me.Text = "DataBase Images"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PicBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim thumbNail As Image
With OpenFileDialog1

.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
.FilterIndex = 2
End With

If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
With PictureBox1
.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
.SizeMode = PictureBoxSizeMode.CenterImage
End With
Dim theImage As New Bitmap(OpenFileDialog1.FileName)
PictureBox1.Image = theImage
thumbNail = theImage.GetThumbnailImage(PictureBox1.Height, PictureBox1.Width, Nothing, Nothing)
PictureBox1.Image = thumbNail
End If
Me.Label1.Text = Me.OpenFileDialog1.FileName.ToString
End Sub

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

If TextBox1.Text = "" Then
MsgBox("Please Enter Name File")
TextBox1.Focus()
Exit Sub
End If

' Open the file
Dim fs As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim s As String = TextBox1.Text
'Read the output in binary reader
Dim r As BinaryReader = New BinaryReader(fs)
'Declare a byte array to save the content of the file to be saved
Dim FileByteArray(CInt(fs.Length - 1)) As Byte
r.Read(FileByteArray, 0, CInt(fs.Length))
Dim sql As String = "INSERT INTO Images (Filename,Photo) VALUES (?,?)"
Dim i As Integer

ListBox1.Items.Add(TextBox1.Text)




MessageBox.Show("Image Succesfully inserted !", "Photo Album", MessageBoxButtons.OK, MessageBoxIcon.Information)


fix:
Exit Sub
End Sub

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

End Sub


Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim arrayImage() As Byte = CType(Me.DataSet11.Tables(0).Rows(Me.ListBox1.SelectedIndex)("photo"), Byte())
Dim ms As New MemoryStream(arrayImage)
With Me.PictureBox1
.Image = Image.FromStream(ms)
.SizeMode = PictureBoxSizeMode.CenterImage

End With
End Sub
End Class

Aamir Mustafa

GeneralRe: storing images into DB Pin
pmarfleet9-Mar-08 4:05
pmarfleet9-Mar-08 4:05 
GeneralRe: storing images into DB Pin
Christian Graus9-Mar-08 11:11
protectorChristian Graus9-Mar-08 11:11 
GeneralRe: storing images into DB Pin
Paul Conrad9-Mar-08 11:53
professionalPaul Conrad9-Mar-08 11:53 
GeneralRe: storing images into DB Pin
Paul Conrad9-Mar-08 11:51
professionalPaul Conrad9-Mar-08 11:51 
GeneralPlease help: BlueTooth and visual studio.net Pin
Jason Wucinski8-Mar-08 22:35
Jason Wucinski8-Mar-08 22:35 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Christian Graus8-Mar-08 22:46
protectorChristian Graus8-Mar-08 22:46 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Jason Wucinski8-Mar-08 22:56
Jason Wucinski8-Mar-08 22:56 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Christian Graus8-Mar-08 23:54
protectorChristian Graus8-Mar-08 23:54 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Jason Wucinski9-Mar-08 1:51
Jason Wucinski9-Mar-08 1:51 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Mark Churchill9-Mar-08 2:06
Mark Churchill9-Mar-08 2:06 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
Jason Wucinski9-Mar-08 6:45
Jason Wucinski9-Mar-08 6:45 
GeneralRe: Please help: BlueTooth and visual studio.net Pin
plural9-Mar-08 9:32
plural9-Mar-08 9:32 
GeneralPlease help with my graduation project Pin
Abdduke8-Mar-08 12:43
Abdduke8-Mar-08 12:43 
GeneralRe: Please help with my graduation project Pin
pmarfleet8-Mar-08 13:34
pmarfleet8-Mar-08 13:34 
GeneralRe: Please help with my graduation project Pin
Abdduke9-Mar-08 6:03
Abdduke9-Mar-08 6:03 
GeneralRe: Please help with my graduation project Pin
pmarfleet9-Mar-08 9:14
pmarfleet9-Mar-08 9:14 
GeneralRe: Please help with my graduation project Pin
Paul Conrad9-Mar-08 11:58
professionalPaul Conrad9-Mar-08 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.