当相同数据输入数据库而不是添加新字段时,数量增加 [英] Quantity increasing when the same data enter to the database rather than adding in a new field

查看:97
本文介绍了当相同数据输入数据库而不是添加新字段时,数量增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以用来盘点的系统,因此,当我在文本框中输入商品ID时,程序会检索商品ID,商品价格,商品ID的数量并显示到网格视图中,存储到另一个表调用库存数据中.这意味着它将数量存储为1,因此,如果再次搜索相同商品ID的记录,则应以数量2存储到库存数据表中.当我键入不同的ID时,它将存储为新记录和数量将为1.

我正在使用访问数据库来完成这项工作

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

推荐答案

实现的伪代码:

Pseudo code to achieve:

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


您好.

如果我没看错,那么您正在使用数据表绑定您的gridview.从数据库中获取数据并将其存储在数据表中时,只需在数据表中添加"OPERATION"列即可.
您需要做的是,添加一个位值以识别行操作.例如,要添加新值,只需在该列中插入0并存储在数据表中即可.完成所有必要的操作后,您可以找到要更新和要添加的值..

这是示例代码:

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:

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();
        }
    }









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







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();
        }
    }


您的问题未清除.
修改您的主表,增加一列使用的数量.将您的使用数量存储到
那个专栏.如果您显示您的物料明细,请按使用的总数量显示您的余额数量.如果您预定您的数量,则只增加一个已使用的数量.
您可以通过此方法达到目标.
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.


这篇关于当相同数据输入数据库而不是添加新字段时,数量增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆