Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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();
                }

               
              }
Posted

1 solution

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
 
Share this answer
 
Comments
IviKAZAZI 18-Feb-12 5:20am    
i used the bool but it happened again.can you send any code pls??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900