【发布时间】:2012-04-06 01:19:41
【问题描述】:
当我在数据库中使用 BCP 数据时,触发器不会被触发。 我应该怎么做才能使触发器有用?我可以只更新数据而不更改值吗?
try
{
//get all data
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
strExcel = string.Format("select * from [{0}$] where xh<>''", sheetName);
OleDbDataAdapter oda = new OleDbDataAdapter(strExcel, strConn);
oda.Fill(ds, sheetName);
//BCP data
using (SqlBulkCopy bcp = new SqlBulkCopy(connectionString))
{
bcp.SqlRowsCopied += new SqlRowsCopiedEventHandler(bcp_SqlRowsCopied);
bcp.BatchSize = 100;//the speed of import
bcp.NotifyAfter = 100;
bcp.DestinationTableName = sheetName;//target table
bcp.WriteToServer(ds.Tables[0]);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
触发器正在跟随。
创建触发器 getAge
关于表名
用于插入、更新
作为
如果更新(生日)
更新表名 set age=DateDiff(year,birthday,getdate())
去
【问题讨论】:
-
另外,应该指出 DATEDIFF(Year, Birthday, GETDATE()) 是一种非常不可靠的返回年龄的方法。尤其是元旦,几乎每个人都会算错年龄