VBSlip 13_2_2015-16



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


Dim db As ADODB.Connection
Dim rec As ADODB.Recordset
Dim str As String

Private Sub Command1_Click()
                Text1.Text = ""
                Text2.Text = ""
                Text3.Text = ""
                Text4.Text = ""
                Text5.Text = ""
End Sub
Private Sub Command2_Click()
                rec.AddNew
                rec!pno = Val(Text1.Text)
                rec!pname = (Text2.Text)
                rec!qty = Val(Text3.Text)
                rec!price = Val(Text4.Text)
                rec!t_price = Val(Text5.Text)
                rec.Update
                rec.Requery
                MsgBox ("data inserted")
End Sub
Private Sub Command3_Click()
                Dim pno As Integer
                Dim qty As Integer
                pno = Val(InputBox("Enter Product number to update"))
                qty = Val(InputBox("Enter Quantity to update"))
                rec.Close
                str = "update prod set qty='" &qty& "' where pno like '" &pno& "'"
                rec.Openstr, db, adOpenDynamic, adLockPessimistic
                MsgBox ("Data Updated")
End Sub
Private Sub Form_Load()
                Set db = New ADODB.Connection
                db.ConnectionString = "DSN=dbprod"
                db.Open
                MsgBox "open"
                Set rec = New ADODB.Recordset
                str = "select * from prod"
                rec.Openstr, db, adOpenDynamic, adLockPessimistic
                Call loaddata
End Sub
Private Sub loaddata()
                Text1.Text = rec.Fields(0)
                Text2.Text = rec.Fields(1)
                Text3.Text = rec.Fields(2)
                Text4.Text = rec.Fields(3)
                Text5.Text = rec.Fields(4)
End Sub
 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.