Hi need help with regards to deducting from customers purchases. The fields look like this:

tblStocks:

Name Type Qty
Pencil 2 15
Pen G-Tech 5

When the customer would purchase 2 pencils, the datagrid field qty would be 13..Does anyone here know how to do this?

you need to give more details like are you maintaining the purchase details?
If yes, is there any relationship between these two?
or Once user clicks on purchase update ur stock table with Currentstock-Qtypurchased and get the new values fromm db and bind again.

it doesnt have any other table. It's just simple table with those fields. Once the user clicks on purchase it should automatically update the stock.

Then you need to take the number how much user has purchased , when he clicks on purchase u need to update this table with new value.

so how will i do that? can u give me sample codes if u don't mind. coz i don't know where to start here

this is my trial but it doesn't work

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim remBal As Double
        Dim strSQL As String
        strSQL = New String("SELECT quantity FROM Paper WHERE Type = '" + ComboBox1.Text + "' ")

        remBal = Val(strSQL) - Val(txtQty.Text)
        TextBox2.Text = remBal


    End Sub

Where ur executing the Query? where command object? how will you send back new value to db?

Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\sabio\My Documents\Photo.accdb")
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim sql As String

i declared that globally

i think i don't have a command object

May I ask what you are building and what are you trying to accomplish by changing the remaining stock in the datagrid?
The reason for asking is that -if I understood correctly - you will face corrupted data soon after launching this. The remaining stock should be decided in the database (or be deducted in the db and get the result back to the front end). The reason for this is that you can't possibly handle multiple requests at the client side, while the db can and it can be a solid check that you don't sell without the appropriate stock.
DO NOT update the db with remaining stock = x value even if you build this to be a single instanse - single user - single PC kind of app. Instead use an approach remaining stock = remaining stock - y value and if you want to display this to user retrieve the new value.

Also if this is a multiuser environment you might want to warn your users that the inventory shown is just for information and that availability will be confirmed with the order submition.

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.