SQL command inserting same value 4X

Hello everyone!

The code below is inserting the same value 4x in SQL server, but I need to insert the value ONCE!

private void textBoxRx_TextChanged(object sender, EventArgs e)
        {
            if (textBoxRx.Text != "DOOR #1 IS OPENED")
            {
                conn.Open();
                comando.CommandText = "INSERT INTO data(door, time) VALUES ('" + "DOOR #1 IS OPENED!" + "', GETDATE())";
                
                comando.ExecuteNonQuery();
                conn.Close();
                //textBoxRxClear();
            }

            

            if (textBoxRx.Text != "DOOR #1 IS CLOSED")
            {
                conn.Open();
                comando.CommandText = "INSERT INTO data(port, time) VALUES ('" + "DOOR #1 IS CLOSED!" + "', GETDATE())";

                comando.ExecuteNonQuery();
                conn.Close();
                //textBoxRx.Clear();
            }

So, the result according to SQL server is:

DOOR IS CLOSED 08032017 DOOR IS CLOSED 08032017 DOOR IS CLOSED 08032017 DOOR IS CLOSED 08032017

Which is wrong. Anyone can help me, please? Thank you.

This fits better in another section of this forum (or even on another forum).

First a question to you. Why do you insert DOOR #1 IS CLOSED! into the database if the text in the textbox is NOT DOOR #1 IS CLOSED! ?? That does not make sense to me.

Next, the TextChanged event fires on every change. So if you first paste DOOR #1 in the textbox, it fires; next you paste IS and it fires, next you paste OPEN and it fires and so on.

I suggest that you put a breakpoint in your textBoxRx_TextChanged handler and inspect what is actually at that stage in the textBox.