protected void Page_Load(object sender, EventArgs e) { GetNames(); }
private void GetNames() { lbNames.Items.Clear(); SqlDependency.Stop(connect); SqlDependency.Start(connect); using (SqlConnection cn = new SqlConnection(connect)) { using (SqlCommand cmd = cn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT FirstName, LastName FROM dbo.[Employees]"; cmd.Notification = null; dep.OnChange += new OnChangeEventHandler(dep_onchange); cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { lbNames.Items.Add(dr.GetString(0) + " " + dr.GetString(1)); } } } } }
public void dep_onchange(object sender, SqlNotificationEventArgs e) { GetNames(); SqlDependency dep = sender as SqlDependency; dep.OnChange -= new OnChangeEventHandler(dep_onchange); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)