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.