【发布时间】:2017-08-18 07:34:19
【问题描述】:
所以我有以下代码(高度简化)-
MySqlCommand CMD = new MySqlCommand(@"INSERT INTO helpdesk.calls Set CallID = @CallID, Viewed = 1, Date = current_timestamp();
SELECT * FROM helpdesk.calls WHERE ID = @CallID", Con);
CMD.Parameters.Add("CallID", MySqlDbType.Int32).Value = ID;
using (MySqlDataReader Reader = CMD.ExecuteReader()) {
if (Reader.Read()) {
RetVal = ToCallHeader(Reader);
} else {
// this never throws as Reader.Read() always returns true.
throw new Exception(string.Format("Call ({0}) not found", ID));
}
}
我在其中插入记录并同时运行选择。问题是,当使用插入语句时,无论是否从 select 语句中选择了任何行,Reader.Read() 都会返回 true。这是设计的行为吗?我是否需要对事务进行两个查询?
【问题讨论】: