更新查询未正确执行

编程入门 行业动态 更新时间:2024-10-10 03:22:57
本文介绍了更新查询未正确执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我做一个任务,我想要执行更新查询我的表名是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();

更多推荐

更新查询未正确执行

本文发布于:2023-10-10 22:08:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479897.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!