SqlDependency查找已更改列的行

时间:2019-06-24 06:48:31

标签: c# sql sqldependency

void LoadData()
        {
            DataTable dtshow = new DataTable();
            DataTable dt = new DataTable();

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            //query get data show in grid

            SqlCommand cmdshow = new SqlCommand("SELECT a,b,c FROM XXX", con);

            //query check database change
            SqlCommand cmd = new SqlCommand("SELECT a,b,c FROM XXX", con);

            cmd.Notification = null;
            SqlDependency de = new SqlDependency(cmd);
            de.OnChange += new OnChangeEventHandler(de_OnChange);

            dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection));

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            dtshow.Load(cmdshow.ExecuteReader(CommandBehavior.CloseConnection));
            dataGridView1.DataSource = dtshow;

        }

嗨,我所有的代码都在上面,

当我从特定行更新“ a”列时,我需要从该行中找到“ b”和“ c”。

我怎么能得到?

谢谢

1 个答案:

答案 0 :(得分:0)

我不确定您使用的是哪种SQL,但可以采用PSQL:

在更新时可以添加一个RETURNING

例如:

  UPDATE xxx SET a = <what ever>
  WHERE <your condition>
  RETURNING b,c;