C#代码:
private void picInward_Click(object sender, EventArgs e)
{
for(DataRow dr in dtData.Rows)
{
UpdateLocation(dr["DocId"].ToString(), Convert.ToInt32(dr["SiteId"].ToString()));
}
}
private void UpdateLocation(string DocId, int LocId)
{
try
{
ArrayList sqlParameterArrayList = new ArrayList();
string strQry = "UpdateDocLoc";
SqlParameter sqpDocId = new SqlParameter("DocId", SqlDbType.VarChar);
sqpDocId.Value = DocId;
sqlParameterArrayList.Add(sqpDocId);
SqlParameter sqpLocId = new SqlParameter("LocId", SqlDbType.Int);
sqpLocId.Value = LocId;
sqlParameterArrayList.Add(sqpLocId);
DBHelper.ExecuteStoredProcedure(strQry, sqlParameterArrayList);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
SQL程序:
CREATE procedure UpdateDocLoc
@DocId as varchar(50),
@LocId as int
AS
BEGIN
update DocMaster set SiteId = @LocId where DocumentID = @DocId
Insert into HSDocMaster(DocId, LocId, ModifiedDate, IsDeleted)
value(@DocId, @LocId, GETDATE(), 0)
END
这只是一个示例代码,我相对有一个非常庞大的过程代码,它必须更新多个表,还有一些插入值在其他表中加上该表有一个触发器,它会在更新时触发。我必须更新近1000个奇数记录,这种重复调用该过程的方法太耗时。是否有更好的方法可以更快地完成这项工作?