private static List <Device_Alert> DoQuery(string sql_str) { List <Device_Alert> rtn = new List <Device_Alert>(); try { DBHelper DBHelper_SqlServer = new DBLink(); using (IDataReader dr = DBHelper_SqlServer.ExecuteReader(sql_str)) { while (dr.Read()) { var p = new Device_Alert(); #region 逐个赋值 p.ID = DBHelper_SqlServer.GetDataValue <string>(dr, "ID"); p.DEVICEID = DBHelper_SqlServer.GetDataValue <string>(dr, "DEVICEID"); p.ALERTID = DBHelper_SqlServer.GetDataValue <string>(dr, "ALERTID"); p.ALERTNAME = DBHelper_SqlServer.GetDataValue <string>(dr, "ALERTNAME"); p.CREATETIME = DBHelper_SqlServer.GetDataValue <string>(dr, "CREATETIME"); p.FINISH_TIME = DBHelper_SqlServer.GetDataValue <string>(dr, "FINISH_TIME"); p.TIME_OF_DURATION = DBHelper_SqlServer.GetDataValue <string>(dr, "TIME_OF_DURATION"); p.SYSTEMFLAG = DBHelper_SqlServer.GetDataValue <string>(dr, "SYSTEMFLAG"); #endregion rtn.Add(p); } } } catch { } return(rtn); }
/// <summary> /// 更新某条数据 /// </summary> /// <param name="t_new"></param> /// <returns></returns> public static bool UpdateOne(Device_Alert t_new) { try { Device_Alert tt = t_new; StringBuilder sb = new StringBuilder(); sb.Append(" update DEVICE_ALERT set "); sb.Append("DEVICEID=@DEVICEID, "); sb.Append("ALERTID=@ALERTID, "); sb.Append("ALERTNAME=@ALERTNAME, "); sb.Append("CREATETIME=@CREATETIME, "); sb.Append("FINISH_TIME=@FINISH_TIME, "); sb.Append("TIME_OF_DURATION=@TIME_OF_DURATION, "); sb.Append("SYSTEMFLAG=@SYSTEMFLAG "); sb.Append(" where ID=@ID "); DbCommand cmd = new SqlCommand(); cmd.CommandText = sb.ToString(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@DEVICEID", DbType.String) { Value = tt.DEVICEID }); cmd.Parameters.Add(new SqlParameter("@ALERTID", DbType.String) { Value = tt.ALERTID }); cmd.Parameters.Add(new SqlParameter("@ALERTNAME", DbType.String) { Value = tt.ALERTNAME }); cmd.Parameters.Add(new SqlParameter("@CREATETIME", DbType.String) { Value = tt.CREATETIME }); cmd.Parameters.Add(new SqlParameter("@FINISH_TIME", DbType.String) { Value = tt.FINISH_TIME }); cmd.Parameters.Add(new SqlParameter("@TIME_OF_DURATION", DbType.String) { Value = tt.TIME_OF_DURATION }); cmd.Parameters.Add(new SqlParameter("@SYSTEMFLAG", DbType.String) { Value = tt.SYSTEMFLAG }); cmd.Parameters.Add(new SqlParameter("@ID", DbType.String) { Value = tt.ID }); foreach (DbParameter p in cmd.Parameters) { p.IsNullable = true; if (p.Value == null) { p.Value = DBNull.Value; } } DBHelper DBHelper_SqlServer = new DBLink(); int val = DBHelper_SqlServer.ExecuteNonQuery(cmd); if (val > 0) { return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
public bool Device_Alert_UpdateOne(Device_Alert t_new) { return(SQL_da_DeviceAlert.UpdateOne(t_new)); }
public bool Device_Alert_InsertOne(Device_Alert t_new) { return(SQL_da_DeviceAlert.InsertNew(t_new)); }