0
の2番目のselectステートメントの値を取得する方法がわかりませんSqlCommand
の2番目のselectステートメントから、最初のテーブルから得られた合計ポイントを合計する値を取得しようとしています。 TOTALPOSSIBLE_SUM変数を使用して5番目の要素をプルしようとしましたが、例外がスローされました。SqlCommand C#
これら2つのSUM値を取得する方法についてのアイデアはありますか?あなたはバッチSQL文の結果を読み込むときおかげ
const int COL_NAME = 1;
const int COL_DUE_DATE = 2;
const int COL_POINTS_POSSIBLE = 3;
const int COL_POINTS_AWARDED = 4;
const int TOTALPOSSIBLE_SUM = 5;
const int TOTALAWARDED_SUM = 6;
// SQL statement to select the columns from the table
command.CommandText =
"SELECT * FROM " +
"[dbo].[Assignments_Table] ORDER BY [PkID] DESC;" +
"SELECT SUM(PointsPossible), SUM(PointsAwarded) " +
"FROM [dbo].[Assignments_Table]";
assignments_view.Items.Clear();
// SQL reader to read the data from the database into the list view
using (SqlDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
Assignment newAssignment = new Assignment();
ListViewItem assignmentItem = new ListViewItem();
// ID
newAssignment.ID = reader.GetInt32(COL_PKID);
// Name
newAssignment.Name = reader.GetString(COL_NAME);
// Due Date
newAssignment.DueDate = reader.GetDateTime(COL_DUE_DATE);
// Possible Points
newAssignment.PointsPossible = reader.GetInt32(COL_POINTS_POSSIBLE);
// Awarded Points
newAssignment.PointsAwarded = reader.GetInt32(COL_POINTS_AWARDED);
newAssignment.TotalPointsPossible = reader.GetInt32(TOTALPOSSIBLE_SUM);
newAssignment.TotalPointsAwarded = reader.GetInt32(TOTALAWARDED_SUM);
}
}
}
ハリ、これは完全にあなたにとても感謝します! – Learn12