récupérer la valeur d'un select
Salut a tous,
Voilà mon problèmes je souhaite faire la somme de toutes les valeurs "total" dans ma table et de l'afficher grâce au label totalHT. Mais je n'y arrive pas. Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
protected void Page_Load(object sender, EventArgs e)
{
string[] totHT;
string totalht = "Select SUM(total) from prodcomm where idprodcomm=1";
int i=0;
SqlConnection conn = new SqlConnection(GetConnectionString());
conn.Open();
SqlCommand cmd = new SqlCommand(totalht, conn);
SqlDataReader mySqDataReader = cmd.ExecuteReader();
if(mySqDataReader["SUMtotal)"]!= System.DBNull.Value){
//récuppère le nom à laide dun cast
string[] totHT = (string[])mySqDataReader["SUM(total"];
}else{
totHT = " ";
}
conn.Close();
int tottt = 0;
for (int i = 0; i < totHT.Length; i++)
{
int totalHorst = int.Parse(totHT[i]);
int tooot = tottt + totalHorst;
tottt = tooot;
}
string toootal = tottt.ToString();
totalHT.Text = toootal;
} |
Merci de m'aider