I have an application I am setting up which has a Web
Services Layer,
Business Logic Layer, Data Access Layer and a Data Layer.
In my Data Layer I have a class that represents an Asset
such as a
computer or laptop. Within that class I have some common
attributes and
properties than I have some attributes and properties
representing
other objects such as Location and User
so I have
public class Asset
{
public Asset(System.Data.DataRow row)
{
this.FromDataRow(row);
}
private int assetId;
private Location location;
private User createdByUser;
public int AssetId
{
get { return assetId; }
set { assetId = value; }
}
public Location Location
{
get { return location; }
set { location = value; }
}
public User CreatedBy
{
get { return createdByUser; }
set { createdByUser = value; }
}
private void FromDataRow(System.Data.DataRow row)
{
this.assetId = Convert.ToInt32(row["AssetId"]);
this.location = (Location)row["Location"];
this.createdByUser = (User)row["CreatedByUser"];
}
}
Then I have a button in which a user clicks it will then go
through a
web service through the business logic and get to the Data
Access Layer
Which gets the following method:
public Data.AssetObjects
GetAssetsByStatusIdUsingObjects(Int32
assetStatusId)
{
SqlConnection con = null;
SqlCommand cmd = null;
SqlDataAdapter da = null;
try
{
con = new
SqlConnection(Common.Configuration.strConn);
con.Open();
cmd = new SqlCommand();
cmd.CommandText =
"usp_AssetsGetAllByStatusId";
cmd.CommandType =
CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue(" AssetStatusId",
assetStatusId);
da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Data.AssetObject datAsset = null;
Data.AssetObjects datAssets = new
Data.AssetObjects();
foreach (DataRow drow in dt.Rows)
{
datAsset = new Data.AssetObject(drow);
datAssets.Add(datAsset);
}
return datAssets;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con = null;
cmd = null;
}
}
Which returns data using the following Stored Procedure:
ALTER PROCEDURE dbo.usp_AssetsGetAllByStatusId
(
AssetStatusId int
)
AS
SET NOCOUNT ON
SELECT
Assets.AssetId,
Assets.SerialNumber,
Assets.AssetTagNumber,
Assets.InventoryId,
Assets.AssetTypeId,
AssetTypes.AssetTypeName,
Assets.AssetStatusId,
AssetStatuses.AssetStatusName,
Assets.ManufacturerId,
Manufacturers.ManufacturerName,
Assets.Model,
Assets.LocationId,
Locations.LocationName,
Assets.BuildingId,
Buildings.BuildingName,
Assets.RoomId,
Rooms.RoomName,
Rooms.Faculty,
Assets.EndUserId,
(EndUsers.FirstName + ' ' + EndUsers.LastName) AS
EndUserName
FROM
AssetTypes RIGHT JOIN
Assets LEFT JOIN
Users AS EndUsers ON Assets.EndUserId = EndUsers.UserId
LEFT JOIN
Locations ON Assets.LocationId = Locations.LocationId LEFT
JOIN
Buildings ON Assets.BuildingId = Buildings.BuildingId LEFT
JOIN
Rooms ON Assets.RoomId = Rooms.RoomId LEFT JOIN
Manufacturers ON Assets.ManufacturerId =
Manufacturers.ManufacturerId
LEFT JOIN
AssetStatuses ON Assets.AssetStatusId =
AssetStatuses.AssetStatusId
ON AssetTypes.AssetTypeId = Assets.AssetTypeId
WHERE
Assets.AssetStatusId = AssetStatusId
RETURN
In doing this I get the following error:
Column 'Location' does not belong to table
Can anyone provide some information in how to do this
correctly or why
I am getting this error.
Thanks to all,
SBProgrammer
|