更新查询未正确执行 [英] Update query not executed properly

查看:75
本文介绍了更新查询未正确执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我做一个任务,我想要执行更新查询我的表名是Medicine_Available_Detail这里iam存储总药物可用列名是可用性,我有一个datagridview,其中我把药物的数量在用户输入特定药物的数量之后然后它表更新作为该药物的可用性 - 数量我写了代码但是没有执行



我的尝试:



  int  quantity = Convert.ToInt16(dataGridView1.Rows [e.RowIndex] .Cells [  Quantity]值)。 

cmd = new OleDbCommand( @ update Medicine_Available_Detail set [可用性] = [可用性] - @ Quantity,其中Medicine_Name = @ Medicine_Name,con);
cmd.Parameters.AddWithValue( @ Quantity,quantity);
cmd.Parameters.AddWithValue( @ Medicine_Name,medicinename);

con.Open();
int n = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show( 记录成功更新);

解决方案

首先,要知道是否有任何行被更新,请检查变量的值

 n 



如果为0则表示没有记录符合您为更新定义的条件。

所以检查varible的值

 medicinename 不存在。



通过查看你的代码,这是你的建议。


你好这里是找到解决方案我使用两个cmd.ExecuteNonQuery();它对我来说很好,dataGridView1_RowLeave事件我写了3个插入查询和一个更新查询而只有一个ExecuteNonQuery而不是使用一个执行非查询我写了两个单独的ExecuteNonQuery与不同的变量



 cmd =  new  OleDbCommand(  update Medicine_Available_Detail set [可用性] = [可用性]  -  @ Quantity其中[Medicine_Name] = @ Medicine_Name,con); 
cmd.Parameters.AddWithValue( @ Quantity,quantity);
cmd.Parameters.AddWithValue( @ Medicine_Name,medicinename);
con.Open();

int n1 = cmd.ExecuteNonQuery();
con.Close();


Hi all,

Iam doing one task where i want to executed update query i have table name is Medicine_Available_Detail here iam storing total medicine available column name is Availability,I have one datagridview where im putting Quantity of that Medicine after user enter Quantity of particular medicine then it table update as Availability-Quantity for that medicine i written a code but its not executed

What I have tried:

int quantity = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells["Quantity"].Value);

                            cmd = new OleDbCommand(@"update Medicine_Available_Detail set [Availability]=[Availability]-@Quantity where Medicine_Name=@Medicine_Name", con);
                            cmd.Parameters.AddWithValue("@Quantity", quantity);
                            cmd.Parameters.AddWithValue("@Medicine_Name", medicinename);

con.Open();
                            int n = cmd.ExecuteNonQuery();
                            con.Close();
                            MessageBox.Show("Record Updated Successfully");

解决方案

First of all, to know if any row is updated or not, check value of your variable

n


if it is 0 means no record is matching the criteria you are defining for update.
So check the value of varible

medicinename

in your table exists on not.

This is all can your suggest by looking at your code.


Hi here is find solution i use two cmd.ExecuteNonQuery();its working fine for me ,dataGridView1_RowLeave event i written 3 insert query and one update query and only one ExecuteNonQuery instead using one Execute non query i written two seprate ExecuteNonQuery with different variable

  cmd = new OleDbCommand("update Medicine_Available_Detail set [Availability]=[Availability]-@Quantity where [Medicine_Name]=@Medicine_Name", con);
                            cmd.Parameters.AddWithValue("@Quantity", quantity);
                            cmd.Parameters.AddWithValue("@Medicine_Name", medicinename);
con.Open();

                            int n1 = cmd.ExecuteNonQuery();
con.Close();


这篇关于更新查询未正确执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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