Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.Data.OleDb
Public Class WF
    Dim cnn As New OleDb.OleDbConnection
    
    Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If

        Dim da As New OleDb.OleDbDataAdapter(" SELECT Husband as [Husband], Wife as [Wife], Husband's Birthday as  [Husband's Birthday], Husband's Age as [Husband's Age], Wife's Birthday as [Wife's Birthday], Wife's Age as [Wife's Age], Husband's Mother as [Husband's Mother], Husband's Father as [Husband's Father], Wife's Father as [Wife's Father], Wife's Mother as [Wife's Mother], Date of Wedding as [Date of Wedding] FROM Wedding ", cnn)

        Dim dt As New DataTable

        da.Fill(dt)

        dgv1.DataSource = dt
        cnn.Close()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim cmd As New OleDb.OleDbCommand

        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If

        cmd.Connection = cnn
        cmd.CommandText = " INSERT INTO Wedding ([Husband], [Wife], [Husband's Birthday], [Husband's Age], [Wife's Birthday], [Wife's Age], [Husband's Mother], [Husband's Father], [Wife's Father], [Wife's Mother], [Date of Wedding]) " & _
                        " VALUES('" & txtHN.Text & "','" & txtWN.Text & "','" & txtHBD.Text & "','" & txtHA.Text & "','" & txtWBD.Text & "','" & txtWA.Text & "','" & txtHM.Text & "','" & txtHF.Text & "','" & txtWF.Text & "','" & txtWM.Text & "','" & txtDoW.Text & "')"
        cmd.ExecuteNonQuery()

        RefreshData()

        cnn.Close()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cnn = New OleDb.OleDbConnection
        Dim sql_query As String
        sql_query = "SELECT * FROM Wedding"

        cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source = " & Application.StartupPath & "\Churh.mdb"

    End Sub
End Class
Posted
Updated 16-Oct-14 9:50am
v2
Comments
Maciej Los 16-Oct-14 15:53pm    
Maciej Los 16-Oct-14 15:56pm    
Close project. Restart your computer and try again. Sounds like the database has been locked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900