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

如何更新c#中的库存数量?,c#,sql-update,C#,Sql Update,在我的windows窗体应用程序中,有两个表,分别是stock和GRN。当我将GRN数据插入数据库时,库存表也应根据收到的GRN数量进行更新。我执行此查询是为了更新它。但如果我需要编辑收到的GRN数量,我如何更新库存表。我在创建GRN时执行此操作是为了更新库存 public void insertquantity(int quantity,string ISBN_No) { DynamicConnection constok = new DynamicConnectio

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

我如何才能做到这一点?

什么是
DynamicConnection
?什么与您当前正在做的工作不兼容?该类包含connection open、sqlcommand、nonquery等methodsOK,但您尚未显示定义。您没有展示sqlquery(…)的功能,也没有告诉我们您遇到的问题是什么。据我们所知,
sqlquery(…)
中的代码什么都不做,而且从不在底层对象上设置查询值。