sorry for my english its kind of its not my primary language..

i am new with programming, and also connecting databases.
i use vb2008 and ms access 2010.

i watched lots of videos with binding source etc on it connecting with database and i found it easy but somehow i am beginning to realize that data bindings have its limitations so i decided to go on codes.

i am doing a project billing and reservation of a resort,
right now i am just editting others' codes of their project then adopting it to mine but i cant seem to get what really it is.

this codes are just for adding/append/insert to my database

Public Class frmReservation
    Dim cnn As New OleDb.OleDbConnection

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Me.txtName.Text = ""
        Me.txtAddress.Text = ""
        Me.txtContact.Text = ""
        Me.txtCottage.Text = ""
        Me.txtRef.Text = ""
        Me.txtDPayment.Text = ""
        Me.txtTime.Text = ""
        Me.txtRoom.Text = ""
        Me.txtMode.Text = ""
        'enable button edit
        'set button add to add label
        Me.btnAdd.Text = "Add"
        '
        Me.txtName.Focus()
    End Sub

    Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            'open connection
            cnn.Open()
        End If

        Dim da As New OleDb.OleDbDataAdapter("Select * from Reservation", cnn)
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        Me.DataGridView1.DataSource = dt

        'close connection
        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
            'open connection if it is not yet open
            cnn.Open()
        End If

        cmd.Connection = cnn

        cmd.CommandText = "INSERT INTO Reservation( R_Fullname, R_Address, R_Contact, R_Time, R_Room, R_Cottage, R_Method, R_Referenceno, R_Amountdp, ReserDate, TransTime) " & _
                        " VALUES(" & Me.txtName.Text & ",'" & Me.txtAddress.Text & "','" & _
                        Me.txtContact.Text & "','" & Me.txtTime.Text & "','" & _
                        Me.txtRoom.Text & "','" & Me.txtCottage.Text & "','" & _
                        Me.txtMode.Text & "','" & Me.txtRef.Text & "','" & _
                        Me.txtDPayment.Text & "','" & Me.txtResDate.Text & "','" & _
                        Me.txtTranstime.Text & "',)"
        cmd.ExecuteNonQuery()

        RefreshData()
        'clear form
        Me.btnClear.PerformClick()

        'close connection
        cnn.Close()
    End Sub
End Class

please i need help.

Don't copy paste from others, only read and try to realize what he/she wants to do and grow a conception about that matter in yourself.

Well, as you say you are a bigginer in vb.net, so I just want to point out the wrongs in your posting.

1) In SQL Statement Put a single quatation Mark ' after Values and remove the ","" at the end." VALUES(" & Me.txtName.Text & ",'" would be " VALUES('" & Me.txtName.Text & ",'" and Me.txtTranstime.Text & "',)" would be Me.txtTranstime.Text & "')".

2) Close/Dispose the command object and Connection object then call the RefreshData() Sub-Procedure.

cmd.ExecuteNonQuery()
cmd.Dispose()

'close connection
cnn.Close()

RefreshData()
'clear form
Me.btnClear.PerformClick()

3) Make your If---ElseIf---EndIf Statement simple and straight forward.

'open the connection if it is closed
If cnn.State = ConnectionState.Closed Then cnn.Open()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.