一切正常,但不起作用的一件事是它正在为每个帐户做笔记,即使没有为该帐户完成/找到任何事情。
for (int j = 0; j < accounts.Length; j++)
{
SqlConnection connection = new SqlConnection(SqlDataSource1.ConnectionString);
SqlCommand SqlComm = new SqlCommand("insert into TableHistory (id, startDate, dueDate, userid, amount, number, needsReview, offer, dateAdded, dateRejected, rejectedBy) " +
"select (select max(id) + 1 from Table1), startDate, dueDate, userid, amount, number, needsReview, offer, dateAdded, GETDATE(), @userID from Table1 where number = @number " +
"delete from Table1 where number = @number", connection);
SqlComm.Parameters.Add("@number", SqlDbType.Int).Value = Convert.ToInt32(accounts[j].ToString());
SqlComm.Parameters.Add("@userID", SqlDbType.Int).Value = userID;
connection.Open();
SqlComm.ExecuteNonQuery();
connection.Close();
NoteAccount note = new NoteAccount("Personal Note", accounts[j].ToString(), userID);
note.makeNote();
}
假设 Account 11 中没有任何内容Table1
。什么都不会失败,因为 insert 语句不会触发,因为 select 语句不返回任何 from Table1
,这很好。
但是note.makeNote();
当不需要添加时,会触发并向帐户添加“个人”注释。如果帐户存在,是否有一种简单的方法可以仅添加注释Table1
?