I need some help understanding how to code for the following scenario: A page can have multiple attributes, by attributes I mean an instrument, a style, and a scoring.
In the database this looks like:
In the C# code this is my class StorePage:
Then to retrieve the StorePage record I have this method:
My question is, how can I add the 2 columns that have multiple values for a single page record in my method GetPage? These are 2 new values, I declared them as arrays since one page can have many of each but I am not sure this is the correct way. I have not added them to the method GetPage because I am not sure how to do this.
public int[] SPAttributeRefID { get; set; }
public int[] AttributeID { get; set; }
In the database this looks like:
C#:
23 trumpet seo 7 meta 26 trumpet.jpg /store/trumpet.jpg blurb 3 footer 1 506
23 trumpet seo 7 meta 26 trumpet.jpg /store/trumpet.jpg blurb 3 footer 2 183
23 trumpet seo 7 meta 26 trumpet.jpg /store/trumpet.jpg blurb 3 footer 3 45
In the C# code this is my class StorePage:
C#:
public class StorePage
{
public int StorePageID { get; set; }
public int SPPreambleID { get; set; }
public string Title { get; set; }
public string SEOTitle { get; set; }
public int ParentStorePageID { get; set; }
public string Meta { get; set; }
public string Image { get; set; }
public string ImageLink { get; set; }
public string Blurb { get; set; }
public int RegionID { get; set; }
public string Footer { get; set; }
public int[] SPAttributeRefID { get; set; }
public int[] AttributeID { get; set; }
}
Then to retrieve the StorePage record I have this method:
C#:
public StorePage GetPage(int StorePageID, int SPPreambleID)
{
StorePage storepage = new StorePage();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("mn_StorePage_GetPage", con))
{
cmd.Parameters.AddWithValue("@StorePageID", SqlDbType.Int).Value = StorePageID;
cmd.Parameters.AddWithValue("@SPPreambleID", SqlDbType.Int).Value = SPPreambleID;
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
storepage.StorePageID = reader.GetInt32(0);
storepage.Title = (reader.IsDBNull(1)) ? string.Empty : reader.GetString(1);
storepage.SEOTitle = (reader.IsDBNull(2)) ? string.Empty : reader.GetString(2);
storepage.ParentStorePageID = (reader.IsDBNull(3)) ? -1 : reader.GetInt32(3);
storepage.Meta = (reader.IsDBNull(4)) ? string.Empty : reader.GetString(4);
storepage.SPPreambleID = (reader.IsDBNull(5)) ? -1 : reader.GetInt32(5);
storepage.Image = (reader.IsDBNull(6)) ? string.Empty : reader.GetString(6);
storepage.ImageLink = (reader.IsDBNull(7)) ? string.Empty : reader.GetString(7);
storepage.Blurb = (reader.IsDBNull(8)) ? string.Empty : reader.GetString(8);
storepage.RegionID = (reader.IsDBNull(9)) ? -1 : reader.GetInt32(9);
storepage.Footer = (reader.IsDBNull(10)) ? string.Empty : reader.GetString(10);
}
}
}
return storepage;
}
My question is, how can I add the 2 columns that have multiple values for a single page record in my method GetPage? These are 2 new values, I declared them as arrays since one page can have many of each but I am not sure this is the correct way. I have not added them to the method GetPage because I am not sure how to do this.
public int[] SPAttributeRefID { get; set; }
public int[] AttributeID { get; set; }