在数据库表的表中插入时的if语句 [英] if statement when insert in the table on database table

查看:75
本文介绍了在数据库表的表中插入时的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源表,供稿结束时将在其中插入数据.我的工作是监视该表,如果插入了任何新记录,我需要从我的(c#程序) 调用存储过程,该存储过程具有一些业务逻辑
我使用访问数据库
..

[edit]已删除了虚假代码块-OriginalGriff [/edit]

解决方案

如果您使用的是数据表,请尝试以下代码

私有void UpdateDataTable(DataTable表,
OleDbDataAdapter myDataAdapter)
{
DataTable xDataTable = table.GetChanges();
//检查DataTable中是否有错误.
如果(xDataTable.HasErrors)
{
//插入代码以解决错误.
}
//解决错误后,请使用DataAdapter更新数据库
myDataAdapter.Update(xDataTable);
}




尝试使用SqlDependency类:
http://stackoverflow.com/questions/5288434/how-to-monitor-sql-server-table-changes-by-using-c [ http://www.dreamincode.net/forums/topic /156991-using-sqldependency-to-monitor-sql-database-changes/ [ http://msdn.microsoft.com/en-us/library/bb522893.aspx [ ^ ]


问候
Robert


看看INSERT 触发器 [ ^ ].


i have a one source table,in which data is inserted when the feed is over. my job is to monitor that table,if any new record inserted i need to call the stored procedure from my (c# program) which has some business logic to it
I use the access database
..

[edit]Spurious code block removed - OriginalGriff[/edit]

解决方案

Please try this code if you are using a datatable

private void UpdateDataTable(DataTable table,
OleDbDataAdapter myDataAdapter)
{
DataTable xDataTable = table.GetChanges();
// Check the DataTable for errors.
if (xDataTable.HasErrors)
{
// Insert code to resolve errors.
}
// After fixing errors, update the database with the DataAdapter
myDataAdapter.Update(xDataTable);
}


Hi,

try to use SqlDependency class:
http://stackoverflow.com/questions/5288434/how-to-monitor-sql-server-table-changes-by-using-c[^]
and
http://www.dreamincode.net/forums/topic/156991-using-sqldependency-to-monitor-sql-database-changes/[^]

but you must study more about service broker:

http://msdn.microsoft.com/en-us/library/bb522893.aspx[^]


Regards
Robert


Have a look at INSERT triggers[^].


这篇关于在数据库表的表中插入时的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆