24.Write a VB program to accept the details of book, store those details into the database and delete the particular record of given book id. (Use InputBox)


Dim C As New Connection
Dim R As New Recordset
Dim S As String
Private Sub cmdAdd_Click()
txtBno.Text = “”
txtBname.Text = “”
txtAuthor.Text = “”
txtPrice.Text = “”

txtBno.SetFocus
End Sub

Private Sub cmdDelete_Click()
Dim id
id = InputBox(“Enter Book number”)
R.Close
S = “delete from tblBook where (bno=” & id & “)”
R.Open S, C, adOpenDynamic, adLockOptimistic
S = “Select * From tblBook”
R.Open S, C, adOpenDynamic, adLockOptimistic
If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtBno.Text = R.Fields(0).Value
txtBname.Text = R.Fields(1).Value
txtAuthor.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
End If
MsgBox “Book Deleted Successfully!”, vbInformation, “Book”

End Sub
Private Sub cmdNext_Click()
R.MoveNext
If Not R.EOF Then
txtBno.Text = R.Fields(0).Value
txtBname.Text = R.Fields(1).Value
txtAuthor.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
Else
MsgBox “No More Records!”, vbInformation, “Book”
End If
End Sub
Private Sub cmdSave_Click()
R.Close
S = “Insert Into tblBook Values(” & Val(txtBno.Text) & “,'” & txtBname.Text & “‘,'” & txtAuthor.Text & “‘, ” & Val(txtPrice.Text) & “)”
R.Open S, C, adOpenDynamic, adLockOptimistic
S = “Select * From tblBook”
R.Open S, C, adOpenDynamic, adLockOptimistic
If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtBno.Text = R.Fields(0).Value
txtBname.Text = R.Fields(1).Value
txtAuthor.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
End If
MsgBox “Book Added Successfully!”, vbInformation, “Book”
End Sub
Private Sub Form_Load()
S = “Select * From tblBook”
C.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\book.mdb;Persist Security Info=False”
R.Open S, C, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtBno.Text = R.Fields(0).Value
txtBname.Text = R.Fields(1).Value
txtAuthor.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s