I am trying to select "food_ItemName" and "food_UnitPrice" from "t_Food" table in SQL Server 2005 using C# and VS 2008.
I have the following code:
private SqlConnection connection;
private void GetDatabaseConnection()
{
string connectionString = @"Server = RZS-F839AD139AA\SQLEXPRESS; Integrated Security = SSPI; Database = HotelCustomerManagementDatabase";
connection = new SqlConnection(connectionString);
connection.Open();
}
public Food PopulateFoodItemListview()
{
GetDatabaseConnection();
string selectFoodItemQuery = @"SELECT food_ItemName, food_UnitPrice FROM t_Food";
SqlCommand command = new SqlCommand(selectFoodItemQuery, connection);
SqlDataReader reader = command.ExecuteReader();
Food food = new Food();
List foodList = new List();
while (reader.Read())
{
food.ItemName.Add(reader.GetString(0));
MessageBox.Show("ItemName: "+ food.ItemName);
food.UnitPrice.Add(reader.GetDouble(1));
MessageBox.Show("UnitPrice: " + food.UnitPrice);
}
connection.Close();
return food;
}
And in "Food" class I have the following code:
public class Food
{
private List itemName = new List();
private List unitPrice = new List();
private double itemUnit;
private Customer foodCustomer = new Customer();
public List ItemName
{
get { return itemName; }
set { itemName = value ; }
}
public List UnitPrice
{
get { return unitPrice; }
set { unitPrice = value; }
}
public double ItemUnit
{
get { return itemUnit; }
set { itemUnit = value; }
}
public double GetItemPrice(double itemUnit, double unitPrice)
{
double itemPrice = itemUnit*unitPrice;
return itemPrice;
}
}
In messageBox it supposed to show Rice, Mutton, Beef and their price 50, 100, 150. But it showhing " ItemName: System.Collections.Generic.List`1[Syste.String] " and " ItemName: System.Collections.Generic.List 1[Syste.Double] " Whats the problem?