Hi guys i have 3 textboxes 1,2,3
textbox1 respresent mobileNo
textbox2 represent email
textbox3 represent roomno
I need to update any textboxes from three based on textchanged event
Suppose i need update room no in textbox3 changed event
room no is 22 i need to changed to 3333 then update in history by insert into statment in textchanged event
it make insert 4 times
first time 3
second time 33
third 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
Anonymous User
06-Apr-2015TextChanged 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.
John Smith
06-Apr-2015this 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..