13. Write a VB program to accept the details of product having fields pno, pname, qty, price totalprice and store it into the database and update the quantity of product having pno is 100. (Don’t use Standard Data controls)


Dim C As New Connection
Dim R As New Recordset
Dim S As String
Dim tot As Integer
Private Sub cmdAdd_Click()
txtPcode.Text = “”
txtPname.Text = “”
txtQty.Text = “”
txtPrice.Text = “”
txtTotal.Text = “”

txtPcode.SetFocus
End Sub
Private Sub cmdNext_Click()
R.MoveNext
If Not R.EOF Then
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
Else
MsgBox “No More Records!”, vbInformation, “Product”
End If
End Sub
Private Sub cmdPrev_Click()
R.MovePrevious
If Not R.BOF Then
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
Else
MsgBox “No More Records!”, vbInformation, “Product”
End If
End Sub

Private Sub cmdSave_Click()
R.Close
S = “Insert Into prodData Values(” & Val(txtPcode.Text) & “,'” & txtPname.Text & “‘,” & Val(txtQty.Text) & “, ” & Val(txtPrice.Text) & “,” & Val(txtTotal.Text) & “)”
R.Open S, C, adOpenDynamic, adLockOptimistic
S = “Select * From prodData”
R.Open S, C, adOpenDynamic, adLockOptimistic
If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
End If
MsgBox “Product Added Successfully!”, vbInformation, “Product”
End Sub

Private Sub cmdUpdate_Click()
R.Close
If txtPcode.Text = 100 Then
S = “Update prodData Set pno = ‘” & txtPname.Text & “‘, pname = ‘” & txtPname.Text & “‘,qty=” & Val(txtQty.Text) & “,price=” & Val(txtPrice.Text) & “‘,totalprice=” & Val(txtTotal.Text) & ” Where pno = ” & Val(txtPcode.Text)
R.Open S, C, adOpenDynamic, adLockOptimistic
S = “Select * From prodData”
R.Open S, C, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
End If
MsgBox “Product Updated Successfully!”, vbInformation, “Product”
Else
S = “Select * From prodData”
R.Open S, C, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
End If
MsgBox “Product Not updated!”, vbInformation, “Product”
End If
End Sub
Private Sub Form_Load()
S = “Select * From prodData”
C.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\prod.mdb;Persist Security Info=False”
R.Open S, C, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
R.MoveFirst
txtPcode.Text = R.Fields(0).Value
txtPname.Text = R.Fields(1).Value
txtQty.Text = R.Fields(2).Value
txtPrice.Text = R.Fields(3).Value
txtTotal.Text = R.Fields(4).Value
End If
End Sub

Private Sub txtPrice_Change()
txtTotal = Val(txtQty.Text) * Val(txtPrice.Text)
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