C#SqlDataReader怎么用
1个回答
推荐于2016-10-30 · 知道合伙人软件行家
关注
展开全部
string cnn = ConfigurationManager.ConnectionStrings["ReportDataService"].ConnectionString;
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = cnn;
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "p_OrderDetailExecute";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SupplierID", SupplierID);
using (var reader = cmd.ExecuteReader())
{
return reader.Cast<IDataRecord>().Select(p => new OrderDetailExecuteData
{
SID = reader.GetInt64(0),
SupplierName = reader.GetString(1),
BillNO=reader.GetString(2),
ProductName = reader.GetString(3),
Spec = reader.GetString(4),
Material = reader.GetString(5),
MadeIn = reader.GetString(6),
Standard =reader.GetString(7),
Unit = reader.GetString(8),
Nums=reader.GetDecimal(9),
Remark = reader.GetString(10),
Price = reader.GetDecimal(11),
SubTotalPrice = reader.GetDecimal(12),
DeliveryDate = reader.GetDateTime(13),
PayPrices = reader.GetDecimal(14),
UnPayPrice = reader.GetDecimal(15),
OrderRemark=reader.GetString(16),
ContractFile = reader.GetString(17),
}).ToList().AsQueryable();
}
}
}
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = cnn;
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "p_OrderDetailExecute";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SupplierID", SupplierID);
using (var reader = cmd.ExecuteReader())
{
return reader.Cast<IDataRecord>().Select(p => new OrderDetailExecuteData
{
SID = reader.GetInt64(0),
SupplierName = reader.GetString(1),
BillNO=reader.GetString(2),
ProductName = reader.GetString(3),
Spec = reader.GetString(4),
Material = reader.GetString(5),
MadeIn = reader.GetString(6),
Standard =reader.GetString(7),
Unit = reader.GetString(8),
Nums=reader.GetDecimal(9),
Remark = reader.GetString(10),
Price = reader.GetDecimal(11),
SubTotalPrice = reader.GetDecimal(12),
DeliveryDate = reader.GetDateTime(13),
PayPrices = reader.GetDecimal(14),
UnPayPrice = reader.GetDecimal(15),
OrderRemark=reader.GetString(16),
ContractFile = reader.GetString(17),
}).ToList().AsQueryable();
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询