public static LSResource GetLSResource(string guid) { LSResource resource = null; //create a connection DbConnection connection = FactoryDB.GetConnection(); //create a command DbCommand cmd = FactoryDB.CreateCommand("Resource_GetByGuid", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(FactoryDB.CreateParameter(cmd, "@guid", guid, DbType.AnsiString, 50)); // execute the command try { connection.Open(); DbDataReader dataReader = null; dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { resource = new LSResource(); resource.resourceID = dataReader.GetInt32(0); resource.labServerGuid = dataReader.GetString(1); resource.labServerName = dataReader.GetString(2); if (!dataReader.IsDBNull(3)) resource.description = dataReader.GetString(3); } } } catch (Exception ex) { throw new Exception("Exception thrown in add permitted experiment", ex); } finally { connection.Close(); } return resource; }
/* */ public static LSResource[] GetLSResources() { List<LSResource> resources = null; //create a connection DbConnection connection = FactoryDB.GetConnection(); //create a command DbCommand cmd = FactoryDB.CreateCommand("Resource_GetAll", connection); cmd.CommandType = CommandType.StoredProcedure; // execute the command try { connection.Open(); DbDataReader dataReader = null; dataReader = cmd.ExecuteReader(); if (dataReader.HasRows) { resources = new List<LSResource>(); while (dataReader.Read()) { LSResource resource = new LSResource(); resource.resourceID = dataReader.GetInt32(0); resource.labServerGuid = dataReader.GetString(1); resource.labServerName = dataReader.GetString(2); if (!dataReader.IsDBNull(3)) resource.description = dataReader.GetString(3); resources.Add(resource); } } } catch (Exception ex) { throw new Exception("Exception thrown in add permitted experiment", ex); } finally { connection.Close(); } return resources.ToArray(); }