對c#和db編程來說很新穎。我接管了別人的代碼。我在嘗試更新數據庫時遇到錯誤。下面的代碼:獲取數據庫錯誤:標準表達式中的數據類型不匹配c#
private void EnableEvent(int eventID)
{
OleDbCommand oleCMD = new OleDbCommand();
oleCMD.Connection = Database.SqlConn();
OleDbTransaction oleTrans = oleCMD.Connection.BeginTransaction();
oleCMD.Transaction = oleTrans;
try
{
StringBuilder sql = new StringBuilder();
sql.AppendFormat("UPDATE Events SET isActive = 1 where EventID='{0}'", eventID);
oleCMD.CommandText = sql.ToString();
// insert the header
oleCMD.ExecuteNonQuery();
oleTrans.Commit();
}
catch(Exception e)
{
MessageBox.Show(e.Message, "Database Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
oleCMD.Connection.Close();
oleCMD.Dispose();
}
}
你能發佈完整的錯誤字符串嗎? – raym0nd
如何獲取更多的錯誤字符串? e.message是「數據類型在標準表達式中不匹配」 – Matt