Below is the structure of my datatable
Id Name Maths Physics Chemistry Score%
1 xyz 10 2 no need
2 abc 8 8 8 24/30*100
3 def 1 no need
If we see the datatable i have three records where i need to calculate percentage of score for only one record in my datatable because if a student passes all the subjects only i need to calculate the percentage if he or she fails in any ano of the subject there is no need to display the percentage how can i do this
I had tried the below code
foreach (DataRow dr1 in dt.Rows)
{
if (!DBNull.Value.Equals(dr1["Maths"]) && !DBNull.Value.Equals(dr1["Physics"]) && !DBNull.Value.Equals(dr1["Chemistry"]))
{
double m1 = Convert.ToDouble(dr1["Maths"]);
double m2 = Convert.ToDouble(dr1["Physics"]);
double m3 = Convert.ToDouble(dr1["Chemistry"]);
double totalscore = m1+m2+m3;
// Set the three values in the new table now.
int maximum = 40;
double total = (totalscore / maximum) * 100;
dr["Score"] = total;
}
}
here i am validating for not getting the datatable cell value empty but still even though cell value is empty it is going into the condition and i am getting error how can i resolve this