public PetShop.Model.Item GetItemById(string ItemId)
{ string sql = "select item.itemid, item.name, item.listprice, product.name, item.image, product.categoryid, product.productid from item inner join product on item.productid = product.productid where item.itemid = @itemid";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ssa"].ConnectionString;
List<PetShop.Model.Item> list = new List<PetShop.Model.Item>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
connection.Open(); command.Parameters.Add("@itemid", SqlDbType.NVarChar).Value = ItemId; SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
PetShop.Model.Item item = new PetShop.Model.Item()
{
ItemId = reader.GetString(0),
Name = reader.GetString(1),
Quantity = reader.GetInt32(2),
ListPrice = reader.GetDecimal(3),
ProductName = reader.GetString(4),
Image = reader.GetString(5),
CategoryId = reader.GetString(6),
ProductId = reader.GetString(7)
};
list.Add(item); }
return list;
} }
{ string sql = "select item.itemid, item.name, item.listprice, product.name, item.image, product.categoryid, product.productid from item inner join product on item.productid = product.productid where item.itemid = @itemid";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ssa"].ConnectionString;
List<PetShop.Model.Item> list = new List<PetShop.Model.Item>();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
connection.Open(); command.Parameters.Add("@itemid", SqlDbType.NVarChar).Value = ItemId; SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
PetShop.Model.Item item = new PetShop.Model.Item()
{
ItemId = reader.GetString(0),
Name = reader.GetString(1),
Quantity = reader.GetInt32(2),
ListPrice = reader.GetDecimal(3),
ProductName = reader.GetString(4),
Image = reader.GetString(5),
CategoryId = reader.GetString(6),
ProductId = reader.GetString(7)
};
list.Add(item); }
return list;
} }
解决方案 »
- c# datagridView的button列
- 在WinFrom中如何通过Http协议Get、Post向服务器获取数据..
- 用Regex.Replace方法...求一正则表达式...!!!!你感动天感动地...........彪泪送高分
- C# 做软件的教程
- 我想给程序来点配置信息,请问使用config还是xml?哪种效果好,实用方便?
- .Net中怎样不用安装Oracle客户端访问Oracle?
- 请大侠们帮帮手,关于网络字节序的问题(HostToNetworkOrder、NetworkToHostOrder)
- 求助,
- C# socket tcp 异步操作 + 心跳包
- 我想做一个类,里面有2个方法,实现对Winform窗体中文本框中数据类型的判断,怎么写,谢谢!
- 在C#怎么获取系统时间到毫秒
- 关于ATM取款机的转账代码怎么写?
=>public List<PetShop.Model.Item> GetItemById(string ItemId)