qadeer37
Well-known member
Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
Dim objCustomer As Customer
Dim objProduct As Products
Try
objCustomer = CType(lstCustomer.SelectedItem, Customer)
objProduct = CType(lstProducts.SelectedItem, Products)
Dim bl As Decimal = objCustomer.Balance
Dim pr As Decimal = objProduct.Price
If bl < pr Then
MessageBox.Show("Your Balance is less then the price of Product: ", "MyShop", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
objCustomer.Balance = bl - pr
MessageBox.Show("You have successfully completed the transaction", "MyShop", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
End Try
End Sub
End Class
I have two questions
1- why not just write queries those manipulate the database rather then creating objects, making changes and then going back to database.

2- now that i have got the new balance and the product oder has been made so every time this happens a query has to be sent to change database or there is any other better why of doing it?
Dim objCustomer As Customer
Dim objProduct As Products
Try
objCustomer = CType(lstCustomer.SelectedItem, Customer)
objProduct = CType(lstProducts.SelectedItem, Products)
Dim bl As Decimal = objCustomer.Balance
Dim pr As Decimal = objProduct.Price
If bl < pr Then
MessageBox.Show("Your Balance is less then the price of Product: ", "MyShop", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
objCustomer.Balance = bl - pr
MessageBox.Show("You have successfully completed the transaction", "MyShop", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
End Try
End Sub
End Class
I have two questions
1- why not just write queries those manipulate the database rather then creating objects, making changes and then going back to database.
2- now that i have got the new balance and the product oder has been made so every time this happens a query has to be sent to change database or there is any other better why of doing it?