SQL命令执行更多然后一次!!!我不想要那个... [英] Sql command executed more then once!!!i dont want that...

查看:75
本文介绍了SQL命令执行更多然后一次!!!我不想要那个...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows Mobile应用程序,我有一个表单,在其中将文本框中的条形码添加到数据库中.但是我希望文本框中的文本保留在那里.按Enter键后插入语句变得很有价值!效果很好,只不过在框中插入的文本要多插入一次,直到下一个条形码.

这是代码:

Im developing a windows mobile app and i have a form where i add a barcode from the textbox to the database.but i want that the text in the text box stays there.the insert statement becomes valuable when enter is pressed!everything goes well,except that the text inside the box is being inserted more then once until the next barcode.

here is the code:

if (e.KeyChar == (char)13)
            {

                _connection.Open();

                SqlCeCommand desc_command = new SqlCeCommand("select description from Items where barcode=@barcode;", _connection);
                desc_command.Parameters.AddWithValue("@barcode", txt_barcode.Text);
                SqlCeDataReader rdr = desc_command.ExecuteReader();
                if (rdr.Read())
                {
                    txt_description.Text = rdr.GetString(0);
                    SqlCeCommand _addcommand = new SqlCeCommand("insert into Inventory values(@barcode,@amount);", _connection);
                    _addcommand.Parameters.AddWithValue("@barcode", txt_barcode.Text);
                    _addcommand.Parameters.AddWithValue("@amount", txt_amount.Text);
                    _addcommand.ExecuteNonQuery();                                      
                    _connection.Close();
                    txt_barcode.SelectAll();                   
                }

                else
                {
                     PlaySound(@"\Windows\Voicbeep", IntPtr.Zero, (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC));
                    txt_description.Text = "--------------";
                    txt_barcode.SelectAll();
                    txt_barcode.Focus();

                    _connection.Close();
                }

               
              }

推荐答案

然后,您需要添加一个类级别的bool来指示数据不是新鲜",或者禁用该按钮.
您可以更改布尔值,或重新启用TextBox.TextChanged事件中的按钮
Then you need to add a class level bool to indicate the data is not "fresh", or disable the button.
You can change the bool, or re-enable the button in the TextBox.TextChanged event


这篇关于SQL命令执行更多然后一次!!!我不想要那个...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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