public List <SMSLog> LoadSMSLogs() { string sql = @"SELECT [ID] , [Phone] , [Message] , [Created] , [Status] FROM [BE_SMSLog]" ; SqlCommand cmd = new SqlCommand(sql, this.conn, this.trans); List <SMSLog> ret = new List <SMSLog>(); SqlDataReader dr = cmd.ExecuteReader(); try { while (dr.Read()) { SMSLog iret = new SMSLog(); if (!Convert.IsDBNull(dr["ID"])) { iret.ID = (Guid)dr["ID"]; } iret.Phone = dr["Phone"].ToString(); if (!Convert.IsDBNull(dr["Message"])) { iret.Message = dr["Message"].ToString(); } if (!Convert.IsDBNull(dr["Created"])) { iret.Created = (DateTime)dr["Created"]; } if (!Convert.IsDBNull(dr["Status"])) { iret.Status = (bool)dr["IStatusD"]; } ret.Add(iret); } } finally { dr.Close(); } return(ret); }
public int InsertSMSLog(SMSLog obj) { string sql = @"INSERT INTO[BE_SMSLog]([ID] , [Phone] , [Message] , [Created] , [Status] ) VALUES(@ID , @Phone , @Message , @Created , @Status )" ; SqlCommand cmd = new SqlCommand(sql, this.conn, this.trans); SqlParameter pID = new SqlParameter("ID", Convert2DBnull(obj.ID)); pID.SqlDbType = SqlDbType.UniqueIdentifier; cmd.Parameters.Add(pID); SqlParameter pPhone = new SqlParameter("Phone", Convert2DBnull(obj.Phone)); pPhone.SqlDbType = SqlDbType.NVarChar; cmd.Parameters.Add(pPhone); SqlParameter pMessage = new SqlParameter("Message", Convert2DBnull(obj.Message)); pMessage.SqlDbType = SqlDbType.NVarChar; cmd.Parameters.Add(pMessage); SqlParameter pCreated = new SqlParameter("Created", Convert2DBnull(obj.Created)); pCreated.SqlDbType = SqlDbType.DateTime; cmd.Parameters.Add(pCreated); SqlParameter pStatus = new SqlParameter("Status", Convert2DBnull(obj.Status)); pStatus.SqlDbType = SqlDbType.Bit; cmd.Parameters.Add(pStatus); return(cmd.ExecuteNonQuery()); }