---
title: "How to repeated insert into history by textchanged event problem"  
description: "How to repeated insert into history by textchanged event problem"  
author: "ahmed salah"  
published: 2015-04-05  
updated: 2015-04-06  
canonical: https://www.mindstick.com/forum/23078/how-to-repeated-insert-into-history-by-textchanged-event-problem  
category: ".net"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# How to repeated insert into history by textchanged event problem

Hi guys i have 3 textboxes 1,2,3

textbox1 respresent mobileNo

textbox2 represent [email](https://www.mindstick.com/articles/12870/10-easy-ways-to-manage-your-business-email-inbox)

textbox3 represent roomno

I need to [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) any textboxes from three based on textchanged [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london)

Suppose i need update room no in textbox3 changed event

room no is 22 i need to changed to 3333 then update in [history](https://yourviews.mindstick.com/view/81373/indian-railways-create-history-with-it-s-shramik-special-trains) by [insert](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) into statment in textchanged event

it make insert 4 times

first time 3

[second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) time 33

[third](https://yourviews.mindstick.com/story/4957/the-significance-of-the-third-eye-in-hinduism-more-than-just-a-symbol) time 333

four time 3333

how to prevent repeated insert into changes to history

```
public void UpdateMobileHistory(string ConnectionString,string SerialNo ,string
     EmployeeNo, string Mobile,string UserID,string DateEdit){
     SqlConnection con = new SqlConnection(ConnectionString);
     SqlCommand cmd = new SqlCommand();
     cmd.Connection = con;
     cmd.CommandType = CommandType.Text;
     cmd.CommandText = "insert into  dbo.HistoryEmployee
     values(@SerialNo,@EmployeeNo ,'Contact
     Data',@DateEdit,@UserID,@Mobile,null,null)";
     cmd.Parameters.Add("@SerialNo", SqlDbType.NVarChar, 20);
     cmd.Parameters.Add("@EmployeeNo", SqlDbType.NVarChar ,20);
     cmd.Parameters.Add("@Mobile", SqlDbType.NVarChar, 50);
     cmd.Parameters.Add("@UserID", SqlDbType.NVarChar ,20);
     cmd.Parameters.Add("@DateEdit", SqlDbType.NVarChar ,50);
     cmd.Parameters["@SerialNo"].Value = SerialNo;
     cmd.Parameters["@EmployeeNo"].Value = EmployeeNo;
     cmd.Parameters["@Mobile"].Value = Mobile;
     cmd.Parameters["@UserID"].Value = UserID;
     cmd.Parameters["@DateEdit"].Value = DateEdit;
     con.Open();
     cmd.ExecuteNonQuery();
     con.Close();
     }
     -----------------
     public string MaxHistoryEmployee(string ConnectionString)
     {
     SqlConnection con = new SqlConnection(ConnectionString);
     SqlCommand cmd = new SqlCommand();
     cmd.Connection = con;
     cmd.CommandType = CommandType.Text;
     cmd.CommandText = "select max(SerialNo)+1 from
     dbo.HistoryEmployee";
     con.Open();
     string commit = Convert.ToString(cmd.ExecuteScalar());
     con.Close();
     return commit;
     }
     -----------------
     private void textBox1_TextChanged(object sender, EventArgs e)
     {
     FleetManagment.Fleet fleetContact1 = new FleetManagment.Fleet();
     string ID = fleetContact1.MaxHistoryEmployee("Data Source=" +
     value1 + ";Initial Catalog=" + value2 + ";User ID=" +
     value3 + ";Password=" + value4 + "");
     fleetContact1.UpdateMobileHistory("Data Source=" + value1 +
     ";Initial Catalog=" + value2 + ";User ID=" + value3 +
     ";Password=" + value4 + "",ID ,textBox4.Text,
     textBox1.Text,label6.Text,label10.Text);
     }
```

this is all my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)

## Replies

### Reply by Anonymous User

Hi,\
\
TextChanged event is called on Focus Lost of textbox, so don't worry about repeated entry in data base as TextChange event will only be fired when you are done typing and moved to next control.\

### Reply by John Smith

why you want to do like this? You can use button click event... \
this is not a good idea on textchange event... you must take command from user to insert record...\
if you really want to do like this then use confirmation message and ask user to press yes or no button...but this popup confirmation message will be annoying\
best to use button click event.. \


---

Original Source: https://www.mindstick.com/forum/23078/how-to-repeated-insert-into-history-by-textchanged-event-problem

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
