如何更新c#中的库存数量?

时间:2018-06-12 05:14:57

标签: c# sql-update

在我的Windows窗体应用程序中有两个表是stock和GRN。当我将GRN数据插入数据库时​​,库存表也应该根据收到的GRN数量更新。我做了这个查询来更新它。但是如果我需要编辑收到的GRN数量。我怎么能更新库存表。我这样做了用于更新库存,创建GRN时

 public void insertquantity(int quantity,string ISBN_No)
    {
        DynamicConnection constok = new DynamicConnection();
        constok.mysqlconnection();
        constok.sqlquery("UPDATE TBL_Stock SET Quantity = IsNULL(Quantity,0) + @quantity where ISBN_No = @ISBN_No");
        constok.cmd.Parameters.Add(new SqlParameter("@quantity", SqlDbType.NVarChar));
        constok.cmd.Parameters["@quantity"].Value = quantity;
        constok.cmd.Parameters.Add(new SqlParameter("@ISBN_No", SqlDbType.NVarChar));
        constok.cmd.Parameters["@ISBN_No"].Value = ISBN_No;
        constok.nonquery();
    }

我需要做这样的事情

 public void editquantity(int quantity, string ISBN_No)
    {
        DynamicConnection constok = new DynamicConnection();
        constok.mysqlconnection();
        constok.sqlquery("UPDATE TBL_Stock  SET Quantity = IsNULL(s.Quantity,0) - (received quntity in GRN table) + (new quntity to be saved to GRN table) where ISBN_No = @ISBN_No and GRN_No=@GRN_No");
        constok.cmd.Parameters.Add(new SqlParameter("@quantity", SqlDbType.NVarChar));
        constok.cmd.Parameters["@quantity"].Value = quantity;
        constok.cmd.Parameters.Add(new SqlParameter("@ISBN_No", SqlDbType.NVarChar));
        constok.cmd.Parameters["@ISBN_No"].Value = ISBN_No;
        constok.nonquery();
    }

我该怎么做?

0 个答案:

没有答案
相关问题