我想标题就是这么说的。
在MS SQL-Table获得新行后,我尝试执行C#代码。有人能给我解释一下怎么做吗?
我用C#-Class 'SqlDependency‘尝试过,但我认为,这不是正确的解决方案,因为C#-代码必须总是重新启动。
我应该用T-SQL和SQL-Agent或类似的东西来尝试它吗?也许我在C #上完全错了,我不知道,我真的需要你的帮助!
我是新来的,所以请对我耐心一点:)
来自奥地利加斯扎的问候
发布于 2016-04-04 21:39:40
如果你想要一个简单的解决方案,你可以试试这个:
使用System.Data.SqlClient连接到您的Database
然后,您可以使用计时器在特定的时间间隔运行"RowCountCheck“:
Timer timer = new Timer(); //using using System.Timers;
timer.Interval = 5000; //Time for 1 interval in milliseconds
timer.AutoReset = true; //Start again when elapsed
timer.Elapsed += Timer_Elapsed; //Method called when timer elapsed
private int _lastRowCount;
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
//Check row Count
//Use your SqlClient here to get the rowCount
if(_lastRowCount < currentRowCount)
{
//Row was added: Do your work here:
}
//Set the currentRowCount as _lastRowCount for the next check
_lastRowCount = "yourValue";
}链接:
http://www.w3schools.com/sql/sql_func_count.asp -如何从SQL表中获取RowCount
https://msdn.microsoft.com/de-de/library/system.data.sqlclient(v=vs.110).aspx - SqlClient
https://stackoverflow.com/questions/36404161
复制相似问题