我一直在尝试从IDataReader
最近获取值,但无法从我查询的第二个表中获取数据。有人可以帮我找到一种方法来获取它们。这是我到目前为止所拥有的:
using (SqlCommand command = new SqlCommand(@"SELECT name, value from Company.dbo.A;SELECT sum(value) from Company.dbo.A ", connection))
{
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()
.Select(x => new LocationInfo()
{
Names = x.GetString(0),
Values = Math.Round(x.GetDouble(1), 2).ToString("#,##0.00"),
ValuesDouble=x.GetDouble(1),
SumVol=x.GetDouble(2)//this line does not work(index out of bounds error)
}).ToList();
}
因此,您如何获得SUM(value) into SumVol
我创建的第二个 SQL 命令public double SumVol { get; set; }
?