CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    29

    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

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to repeated insert into history by textchanged event problem

    Again, please use code tags. Also, when someone takes the time to respond to your posts, please at least acknowledge that you've seen the reply.
    Last edited by Arjay; April 6th, 2015 at 01:24 PM.

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to repeated insert into history by textchanged event problem

    Don't do the insert from the text changed event. That event will fire with every change so you can get a lot more inserts than you want. You need to change the way you are thinking and trigger the insert another way.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: How to repeated insert into history by textchanged event problem

    The TextChanged event is simple the wrong event to handle that problem.
    I would use the keydown Event and checking for the 'Enter' key. When you then press the enter key in the end of entering Text to thr box, the whole text cousd be used to do the enty into your History
    .Do you get the idea or do you need a code snipped?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #5
    Join Date
    Jan 2010
    Posts
    1,133

    Re: How to repeated insert into history by textchanged event problem

    Or, in case the user is allowed, but not required, to press enter, you can additionally handle the LostFocus event.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured