I have an application implemented in C#.NET and SQLite database. I need to count some values of a columns (status) of database table (fruit). The table is like following.
Id B M status
1 10 101 2
2 11 102 2
3 11 103 0
4 12 104 2
5 13 105 2
6 13 105 2
7 14 106 2
8 14 106 2
9 14 106 2
10 14 106 2
I have used following methods to extract the values from the table and show output.
public void CountingValues()
{
string strA, strB, strC;
double Total;
strA = countA();
strB = countB();
strC = countC();
MessageBox.Show(strA.ToString());
MessageBox.Show(strB.ToString());
MessageBox.Show(strC.ToString());
}
public string countA()
{
return GetData("SELECT COUNT(status) FROM fruit WHERE status = 2;");
}
public string countB()
{
return GetData("SELECT COUNT(status) FROM fruit WHERE status = 1;");
}
public string countC()
{
return GetData("SELECT COUNT(status) FROM fruit WHERE status = 0;");
}
private String GetData(String cmd)
{
String result = "";
SQLiteCommand command = new SQLiteCommand(connection);
command.CommandText = cmd;
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
result = reader[0].ToString();
}
reader.Dispose();
command.Dispose();
return result;
}
The results of strA, strB and strC should be 9, 0, and 1 respectively. But, it is showing 4, 0, and 6. Could anyone tell me please what is wrong here ?
Aucun commentaire:
Enregistrer un commentaire