我正在尝试在网页上使用服务,但项目符号列表打印"ASPWebApp.CottagesServiceReference.Cottages"或System.collections.Generic.List 1. 显然,我希望它显示从服务的选择查询中获取的项目。
protected void BtnID_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(TextBoxID.Text);
try
{
List<ASPWebApp.CottagesServiceReference.Cottages> cottages = ws.GetCottageInfoByID(id).ToList();
ListItem cottage = new ListItem(String.Join(".", cottages));
BulletedList1.Items.Add(cottage);
BulletedList1.DataSource = cottages;
BulletedList1.DataBind();
}
catch (Exception a)
{
Console.WriteLine(a);
}
}
服务
public List<Cottages> GetCottageInfoByID(int id)
{
List<Cottages> cottage = new List<Cottages>();
SqlConnection conn = new SqlConnection(dataSource);
string sqlQuerySelectCottageInfo = "SELECT Cottage_Name as 'Name', Cottage_Location as Location, No_Of_Rooms as Rooms, Description, Cost_Per_Night as Cost FROM dbo.Cottages where Cottage_ID = @id";
SqlCommand cmd = new SqlCommand(sqlQuerySelectCottageInfo);
cmd.Parameters.AddWithValue("@id", id);
conn.Open();
cmd.Connection = conn;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
if (!reader.HasRows)
{
throw new Exception("No Cotteges Found");
}
else
{
cottage.Add(new Cottages()
{
Name = (reader[("Name")].ToString()),
Location = (reader[("Location")].ToString()),
Rooms = Convert.ToInt32(reader[("Rooms")]),
Cost = Convert.ToDecimal(reader[("Cost")]),
Description = (reader[("Description")].ToString()),
});
}
}
reader.Close();
conn.Close();
return cottage;
}
江户川乱折腾
倚天杖
相关分类