Hi! i wanted to implement ienumerable in my code so that it is readonly but i don't know where to possibly implement it. So far i haven't found any solution in the internet that might answer my problem. As of now, i have only used List and wanted to integrate ienumerable in my code. Also, feel free to suggest anything if you notice bad coding practices.
What I have tried:
public static List<GuitarItems> GetGuitarItems(string itemCategory)
{
List<GuitarItems> list = new List<GuitarItems>();
string query = string.Format("SELECT * FROM guitarItems WHERE brand LIKE @brand");
try
{
conn1.Open();
command1.CommandText = query;
command1.Parameters.Add(new SqlParameter("brand", itemCategory));
SqlDataReader reader = command1.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string type = reader.GetString(1);
string brand = reader.GetString(2);
string model = reader.GetString(3);
double price = reader.GetDouble(4);
string itemimage1 = reader.GetString(5);
string itemimage2 = reader.GetString(6);
string description = reader.GetString(7);
string necktype = reader.GetString(8);
string body = reader.GetString(9);
string fretboard = reader.GetString(10);
string fret = reader.GetString(11);
string bridge = reader.GetString(12);
string neckpickup = reader.GetString(13);
string bridgepickup = reader.GetString(14);
string hardwarecolor = reader.GetString(15);
GuitarItems gItems = new GuitarItems(id, type, brand, model, price, itemimage1, itemimage2, description, necktype, body,
fretboard, fret, bridge, neckpickup, bridgepickup, hardwarecolor);
list.Add(gItems);
}
}
finally
{
conn1.Close();
command1.Parameters.Clear();
}
return list;
}
And here is the other code:
private void FillPage()
{
List<GuitarItems> itemList = new List<GuitarItems>();
List<string> itemListPage = new List<string>();
itemList = ConnectionClassGuitarItems.GetGuitarItems(brandType);
StringBuilder sb = new StringBuilder();
foreach (GuitarItems gList in itemList)
{
itemListPage.Add("GuitarItemsIbanezDetails" + (x + 1) + ".aspx");
sb.Append(
string.Format(
@"
<div class='one-two'>
<a href='{3}' runat='server'><img runat='server' src='{0}'/></a>
<div class='content'>
<div id='label'>{1} {2}</div>
</div>
</div>", gList.ItemImage1, gList.Brand, gList.Model, itemListPage[x]));
x++;
}
lblOutput.Text = sb.ToString();
}