Pages

Saturday, 21 January 2017

Image Save Using VB.Net in Access

Image Save Using VB.Net in Access

Control List

  • Three Form (MDI,save and Show)
  • Text box , open file dialog ,button on save button
  • Gridview,Picture Box , Label on show form

MDI Code :


Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        frmAdd.MdiParent = Me
        frmAdd.Show()
    End Sub

    Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.Click
        frmShow.MdiParent = Me
        frmShow.Show()
    End Sub

Save Form Code 

Save Form

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtName.Text = "" Or txtcity.Text = "" Or OpenFileDialog1.FileName = "OpenFileDialog1" Then
            MsgBox("Please  provide all Data")
            If txtcity.Text = "" Then
                txtcity.Focus()
            ElseIf txtName.Text = "" Then
                txtName.Focus()
            ElseIf OpenFileDialog1.FileName = "OpenFileDialog1" Then
                Button1.Focus()
            End If
        Else
            Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=girfa.accdb")
            Dim com As New OleDbCommand
            Try
                com.Connection = con
                con.Open()
                com.CommandText = "insert into stu (sname,city,pic) values('" & txtName.Text & "','" & txtcity.Text & "','" & System.IO.Path.GetFileName(OpenFileDialog1.FileName) & "')"
                com.ExecuteNonQuery()
                FileCopy(OpenFileDialog1.FileName, Application.StartupPath & "\image\" & System.IO.Path.GetFileName(OpenFileDialog1.FileName))
                MsgBox("Record Saved")
                txtName.Text = ""
                txtName.Focus()
                txtcity.Text = ""
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                con.Close()
            End Try
        End If       
    End Sub

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

    Private Sub frmAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        System.Diagnostics.Process.Start("http://girfahelp.blogspot.in/p/vbnet-tutorial.html")

    End Sub

Show Form Code 

Show Form


Private Sub frmShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
        System.Diagnostics.Process.Start("http://girfahelp.blogspot.in/p/vbnet-tutorial.html")

    End Sub

    Private Sub frmShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'GirfaDataSet.stu' table. You can move, or remove it, as needed.
        'Me.StuTableAdapter.Fill(Me.GirfaDataSet.stu)
        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=girfa.accdb")
        Dim com As New OleDbCommand("select * from stu", con)
        Try
            com.CommandType = CommandType.Text
            Dim da As New OleDbDataAdapter(com)
            Dim ds As New DataSet()
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)

    End Sub

    Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick
        Dim dr As DataGridViewSelectedRowCollection
        dr = DataGridView1.SelectedRows()
        'lblid.Text = dr.Item(0).Cells(1).Value.ToString()
        lblroll.Text = dr.Item(0).Cells(0).Value.ToString
        lblName.Text = dr.Item(0).Cells(1).Value.ToString
        lblCity.Text = dr.Item(0).Cells(2).Value.ToString
        PictureBox1.Image = Image.FromFile(Application.StartupPath & "/image/" & dr.Item(0).Cells(3).Value.ToString)

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        System.Diagnostics.Process.Start("http://girfahelp.blogspot.in/p/vbnet-tutorial.html")

    End Sub

Download Source Code 
Next Project


No comments:

Post a Comment