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
'check whether add new or update
If MsgBox("Do you want save?", vbInformation + vbYesNo) = vbYes Then
If Me.txtstdID.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = "INSERT INTO tblResidence(ReID, Previous, Present, Reading, Amount, Total_Amount, Date) " & _
" VALUES('" & Me.txtstdID.Text & ",'" & _
Me.txtPrev.Text & "','" & Me.txtPresent.Text & "','" & _
Me.txtRead.Text & "','" & _
Me.txtAmount.Text & "','" & Me.txtTAmount.Text & "','" & _
Me.txtDate.Text & "')"
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "UPDATE tblResidence " & _
", ReId='" & Me.txtstdID.Text & "'" & _
", Previous='" & Me.txtPrev.Text & "'" & _
", Present='" & Me.txtPresent.Text & "'" & _
", Reading='" & Me.txtRead.Text & "'" & _
", Amount='" & Me.txtAmount.Text & "'" & _
", Total_Amount='" & Me.txtTAmount.Text & "'" & _
", Date='" & Me.txtDate.Text & "'" & _
" WHERE ReID=" & Me.txtstdID.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
Me.ReloadRecords()
'clear form
Me.btnClear.PerformClick()
ElseIf vbNo Then
End If
'close connection
cnn.Close()
End Sub
jomitz03 0 Newbie Poster
jomitz03 0 Newbie Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
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.