public static int Insert(Database db, TaskInfo taskInfo) { StringBuilder sbField = new StringBuilder(); StringBuilder sbValue = new StringBuilder(); sbField.Append("INSERT INTO TaskInfo("); sbValue.Append("values("); sbField.Append("TaskId"); sbValue.AppendFormat("{0}", taskInfo.TaskId); sbField.Append(",CameraId"); sbValue.AppendFormat(",{0}", taskInfo.CameraId); sbField.Append(",DecoderId"); sbValue.AppendFormat(",{0}", taskInfo.DecoderId); sbField.Append(",Status"); sbValue.AppendFormat(",{0}", taskInfo.Status); sbField.Append(",HappenDateTime"); sbValue.AppendFormat(",'{0}')", taskInfo.HappenDateTime == null ? DateTime.Now : taskInfo.HappenDateTime); string cmdText = sbField.ToString() + " " + sbValue.ToString(); try { cmdText = cmdText.Replace("\r\n", ""); return db.ExecuteNonQuery(CommandType.Text, cmdText); } catch (Exception ex) { throw ex; } }
public int Insert(ref string errMessage, TaskInfo taskInfo) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; try { return TaskDataAccess.Insert(db, taskInfo); } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return -1; } }