0
我有表名爲Products和類別,產品表的行包括這樣的數據之一:創建關係類對象
ProductId,ProductName,CategoryId
和類別包括
CategoryId,CategoryInfo
所以我m到處使用ExecudeReader()
行使用ado.net像
List<ProductEntity> lst = new List<ProductEntity>();
using (SqlConnection connection = new SqlConnection(constr))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = "select ProductId,ProductName,CategoryId from Products";
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
lst.Add(new ProductEntity()
{
ProductId = int.Parse(reader[0].ToString()),
ProductName= reader[1].ToString(),
CategoryId=int.Parse(reader[2].ToString())
});
}
}
}
但我想從Cat得到CategoryInfo同樣沒有使用ExecuteReader()
。如果是,我可以爲產品和類別創建一個實體類我該怎麼做?或者存在另一個最佳實踐?
cmdText作爲命令文本時有什麼值?如果可能的話, – MarcinJuraszek 2013-03-13 07:20:22
使用連接 – TalentTuner 2013-03-13 07:21:48