Sqldependency
onchangeasp.net
成功触发,我可以获取更新的数据,Dataset
但是当它绑定DataSet
到Gridview
它时,它不会刷新自身。
此外,asp.net
事件触发时不会触发任何页面生命周期事件SqlDependency
。
protected void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
SqlDependency dependency = (SqlDependency)sender;
dependency.OnChange -= dependency_OnChange;
UpdatePanel1.Update();
connstr = "server=66.226.75.158\\SQLEXPRESS;database=sqldependencydb;User id= sqldependencyuser01;Password= yewtee#123";
string ssql = "select EmployeeID,FirstName from dbo.EmployeeList";
if (connection == null)
connection = new SqlConnection(connstr);
if (command == null)
command = new SqlCommand(ssql, connection);
if (myDataSet == null)
myDataSet = new DataSet();
myDataSet.Clear();
command.Notification = null;
Label1.Text = System.DateTime.Now.ToString();
adapter = new SqlDataAdapter(command);
adapter.Fill(myDataSet, "dbo.EmployeeList");
GridView1.DataSource = myDataSet;
GridView1.DataMember = "dbo.EmployeeList";
GridView1.DataBind();
}