Programming for Everybody: vb.net:update
Showing posts with label vb.net:update. Show all posts
Showing posts with label vb.net:update. Show all posts

Programming VB.net: Video connect access database with datagridview, image, music and video( source code)

 




Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        OpenFileDialog1.Filter = "Image|*.png;*.jpg;*.bmp"

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

            TextBox2.Text = OpenFileDialog1.FileName

            PictureBox1.Image = Image.FromFile(TextBox2.Text)

        End If

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        OpenFileDialog1.Filter = "Voice|*.mp3;*.wma;*.Mp4"

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

            TextBox3.Text = OpenFileDialog1.FileName

            AxWindowsMediaPlayer1.URL = TextBox3.Text

        End If

    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'TODO: This line of code loads data into the 'DictionaryDataSet.Table1' table. You can move, or remove it, as needed.

        Me.Table1TableAdapter.Fill(Me.DictionaryDataSet.Table1)


    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        Table1BindingSource.AddNew()

        PictureBox1.Image = Nothing

        AxWindowsMediaPlayer1.currentPlaylist.clear()

    End Sub


    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

        Table1BindingSource.EndEdit()

        Table1TableAdapter.Update(DictionaryDataSet)

        Me.Table1TableAdapter.Fill(Me.DictionaryDataSet.Table1)

    End Sub


    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(2).Value.ToString)) Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(DataGridView1.CurrentRow.Cells(2).Value.ToString)

        End If

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(3).Value.ToString)) Then

            AxWindowsMediaPlayer1.currentPlaylist.clear()

        Else

            AxWindowsMediaPlayer1.URL = DataGridView1.CurrentRow.Cells(3).Value.ToString

        End If

    End Sub


    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

        Table1TableAdapter.Search(DictionaryDataSet.Table1, TextBox1.Text)


    End Sub


    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click

        Table1BindingSource.RemoveCurrent()

        Table1TableAdapter.Update(DictionaryDataSet)

        PictureBox1.Image = Nothing

        AxWindowsMediaPlayer1.currentPlaylist.clear()

    End Sub


    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        Table1BindingSource.MovePrevious()

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(2).Value.ToString)) Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(DataGridView1.CurrentRow.Cells(2).Value.ToString)

        End If

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(3).Value.ToString)) Then

            AxWindowsMediaPlayer1.currentPlaylist.clear()

        Else

            AxWindowsMediaPlayer1.URL = DataGridView1.CurrentRow.Cells(3).Value.ToString

        End If


    End Sub


    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

        Table1BindingSource.MoveNext()

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(2).Value.ToString)) Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(DataGridView1.CurrentRow.Cells(2).Value.ToString)

        End If

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(3).Value.ToString)) Then

            AxWindowsMediaPlayer1.currentPlaylist.clear()

        Else

            AxWindowsMediaPlayer1.URL = DataGridView1.CurrentRow.Cells(3).Value.ToString

        End If


    End Sub


    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click

        Table1BindingSource.MoveFirst()

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(2).Value.ToString)) Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(DataGridView1.CurrentRow.Cells(2).Value.ToString)

        End If

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(3).Value.ToString)) Then

            AxWindowsMediaPlayer1.currentPlaylist.clear()

        Else

            AxWindowsMediaPlayer1.URL = DataGridView1.CurrentRow.Cells(3).Value.ToString

        End If

    End Sub


    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

        Table1BindingSource.MoveLast()

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(2).Value.ToString)) Then

            PictureBox1.Image = Nothing

        Else

            PictureBox1.Image = Image.FromFile(DataGridView1.CurrentRow.Cells(2).Value.ToString)

        End If

        If (String.IsNullOrEmpty(DataGridView1.CurrentRow.Cells(3).Value.ToString)) Then

            AxWindowsMediaPlayer1.currentPlaylist.clear()

        Else

            AxWindowsMediaPlayer1.URL = DataGridView1.CurrentRow.Cells(3).Value.ToString

        End If

    End Sub


    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click

        Close()

    End Sub

End Class

Visual Basic.NET: insert, update, delete and search using access database and print datagridview

 



Imports System.Data.OleDb

Public Class Form3

    Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\listview.accdb")

    Private Sub bind_data()

        Dim cmd1 As New OleDbCommand("Select * from table1", conn)

        Dim da As New OleDbDataAdapter

        da.SelectCommand = cmd1

        Dim table1 As New DataTable

        table1.Clear()

        da.Fill(table1)

        DataGridView1.DataSource = table1


    End Sub


    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles Me.Load

        bind_data()

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim strsql As String

        strsql = "Insert into table1(id,firstname,lastname,sum1)Values(@id,@firstname,@lastname,@sum1)"

        Dim cmd2 As New OleDbCommand(strsql, conn)

        cmd2.Parameters.AddWithValue("@id", TextBox1.Text)

        cmd2.Parameters.AddWithValue("@firstname", TextBox2.Text)

        cmd2.Parameters.AddWithValue("@lastname", TextBox3.Text)

        cmd2.Parameters.AddWithValue("@sum1", TextBox4.Text)

        conn.Open()

        cmd2.ExecuteNonQuery()

        conn.Close()

        bind_data()



    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        TextBox1.Text = ""

        TextBox2.Text = ""

        TextBox3.Text = ""

        TextBox4.Text = ""


    End Sub


    Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        Dim index As Integer

        index = e.RowIndex

        Dim selectedrow As DataGridViewRow = DataGridView1.Rows(index)

        TextBox1.Text = selectedrow.Cells(0).Value.ToString

        TextBox2.Text = selectedrow.Cells(1).Value.ToString

        TextBox3.Text = selectedrow.Cells(2).Value.ToString

        TextBox4.Text = selectedrow.Cells(3).Value.ToString


    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        Dim cmd4 As New OleDbCommand("Update table1 set firstname='" & TextBox2.Text & "',lastname='" & TextBox3.Text & "',sum1=" & TextBox4.Text & " where id=" & TextBox1.Text & "", conn)

        conn.Open()

        cmd4.ExecuteNonQuery()

        conn.Close()

        bind_data()

    End Sub


    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

        Dim cmd5 As New OleDbCommand("delete from table1 where id=@id", conn)

        cmd5.Parameters.AddWithValue("@id", TextBox1.Text)

        conn.Open()

        cmd5.ExecuteNonQuery()

        conn.Close()

        bind_data()

    End Sub


    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click

        PrintPreviewDialog1.Document = PrintDocument1

        PrintPreviewDialog1.PrintPreviewControl.Zoom = 1

        PrintPreviewDialog1.ShowDialog()


    End Sub


    Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim imagebmp As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)

        DataGridView1.DrawToBitmap(imagebmp, New Rectangle(0, 0, Me.DataGridView1.Width, Me.DataGridView1.Height))

        e.Graphics.DrawImage(imagebmp, 120, 20)

    End Sub


    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        Dim cmd1 As New OleDbCommand("Select * from table1 where firstname like '%' +@parm1+ '%' ", conn)

        cmd1.Parameters.AddWithValue("@parm1", TextBox5.Text)

        Dim da As New OleDbDataAdapter

        da.SelectCommand = cmd1

        Dim table1 As New DataTable

        table1.Clear()

        da.Fill(table1)

        DataGridView1.DataSource = table1

    End Sub

End Class