SqlConnection conn = new SqlConnection("Data Source=A-E7F834CA56374;Initial Catalog=company;Integrated Security=True"); SqlCommand cmd = new SqlCommand(); System.Timers.Timer timer = null; protected void StartTimer_Click(object sender, EventArgs e) { if (timer == null) { timer = new System.Timers.Timer(10000); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Enabled = true; timer.Start(); } } void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { cmd.Connection = conn; conn.Open(); cmd.CommandText = "Select * from employee where id='" + txtID.Text + "'"; SqlDataReader dr = cmd.ExecuteReader(); if (!dr.HasRows) { dr.Close(); cmd.CommandText = "Insert into employee Values('" + txtID.Text + "','" + txtName.Text + "','" + txtSal.Text + "','" + txtDept.Text + "')"; } else { dr.Close(); cmd.CommandText = "Update employee set name='" + txtName.Text + "',salary='" + txtSal.Text + "',city='" + txtDept.Text + "' where id='" + txtID.Text + "'"; } cmd.ExecuteNonQuery(); conn.Close(); } protected void StopTimer_Click(object sender, EventArgs e) { timer.Stop(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)