本文介绍了SQL命令不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好帅哥

我有此代码
它不会说库存不足"
我不明白哪里出了问题.
请帮助
我正在使用c#

Hello dudes

I have this code
It does not say ''There are not enough items in stock''
I cant understood where is problem.
please help
Im using c#

SqlCommand cmd1 = new SqlCommand("IF (Select UnitsInStock from Products WHERE BarCode=@BarCode) > @Quantity BEGIN UPDATE Products SET UnitsInStock=(UnitsInStock-@Quantity) WHERE BarCode=@BarCode END ELSE BEGIN PRINT ''There are not enough items in stock''END", new SqlConnection(Program.ConnectionString));
            cmd1.Connection.Open();
            for (int i = 0; i < dtbProducts.Rows.Count; i++)
            {
                cmd1.Parameters.AddWithValue("Quantity", (int)dtbProducts.Rows[i]["Quantity"]);
                cmd1.Parameters.AddWithValue("BarCode", dtbProducts.Rows[i]["BarCode"].ToString());
                cmd1.ExecuteNonQuery();
                cmd1.Parameters.Clear();
            }

            cmd1.Connection.Close();
            cmd.Connection.Close();
            this.Close();

        }

推荐答案



这篇关于SQL命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 22:35