Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a system which can used to take stocks, so when i enter the Item id in the text box, program retrieve the item-name, item-price, Qty of the Item ID and display into the Grid View and it is stored into the another table call stock-data. that means it stores the qty as a 1, so if the same record of the item ID searched again, it should stored to the stock-data table as qty 2. when i type the different id,it should store as new record and qty will be 1.

i am using the access database to do this work
Posted
Updated 21-Feb-12 16:27pm
v2

Pseudo code to achieve:

VB
If (ItemID exists in stock-data)
  Increment qty by 1 for ItemID record
Else
  Add a new record for ItemID with qty=1
End If
 
Share this answer
 
Comments
Mano0114 22-Feb-12 1:03am    
MAY I KNOW THE CODE FOR HOW TO CHECK WETHER THE ITEM ID EXIST OR NOT IN c#
Hi there.

If I am not wrong then you are using data table to bind your gridview. While fetching the data from database and storing in the data table just add a "OPERATION" column to the data table..

What you need to do is, add a bit value to recognize the row operation. For example for adding new values just insert 0 in that column and store in the datatable. After doing all the necessary operation you can find the values which to be updated and which to be added..

Here is the sample code:

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _objEmpDetails = new clsEmpDetails();
            _dtEmpDetails = _objEmpDetails.fnGetDetails();

            //Adding a new column to the table which will store the operation details
            //For new insert it will store 1
            //For updating the existing record it will store 0
            _dtEmpDetails.Columns.Add("Operation", typeof(string));
            Session["EmpDetails"] = _dtEmpDetails;
            fnBindEmpDetails();
        }
    }




C#
private void fnBindEmpDetails()
    {
        _dtEmpDetails = new DataTable();
        _dtEmpDetails = Session["EmpDetails"] as DataTable;
        gvEmpDetails.DataSource = _dtEmpDetails;
        gvEmpDetails.DataBind();
    }



C#
protected void gvEmpDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "AddNew")
        {
            _dtEmpDetails = new DataTable();
            _dtEmpDetails = Session["EmpDetails"] as DataTable;
            string strID = ((TextBox)gvEmpDetails.FooterRow.Cells[0].FindControl("txtInsID")).Text;
            string strName = ((TextBox)gvEmpDetails.FooterRow.Cells[1].FindControl("txtInsName")).Text;
            string strAddress = ((TextBox)gvEmpDetails.FooterRow.Cells[1].FindControl("txtInsAddress")).Text;
            _dtEmpDetails.Rows.Add(strID, strName, strAddress, "0");
            Session["EmpDetails"] = _dtEmpDetails;
            fnBindEmpDetails();
        }
    }
 
Share this answer
 
your question is not cleared.
modify your primary table add one column more qty used . store your use qty into
that column . wen u display your item detail display your balance qty by total qty-used qty.wen u book your qty just increase one in used qty.
u can achieve your result through this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900