J Vs

J Vs

  • 1.7k
  • 52
  • 3k

how to select the maximum value from multiple columns c#

Aug 6 2019 1:31 AM
I have a Access DB with multiple columns, 
 
 Mark1 Mark2 Mark3 Mark4 Mark5
 99 87 78 78 79
 
I need to get the max value and display it in a textbox
then I need to get the avg value and display it in a text box 
 
here is my code:please help with the part as bold
  1. connection.Open();  
  2. OleDbCommand command = new OleDbCommand();  
  3. command.Connection = connection;  
  4. string query = "select* from Students WHERE Firstname LIKE '" + tbsearchid.Text + "' OR ID1 like '" + tbsearchid.Text + "' ";  
  5. command.CommandText = query;  
  6.   
  7.   
  8. OleDbDataReader reader = command.ExecuteReader();  
  9. while (reader.Read()) {  
  10.  tbFname.Text = reader["Firstname"].ToString();  
  11.  tbLname.Text = reader["Lastname"].ToString();  
  12.   
  13.  string course1Text = reader["Course1"].ToString(), course2Text = reader["Course2"].ToString();  
  14.  tbmulti.Text = "Course1: " + course1Text + Environment.NewLine + "Course2: " + course2Text;  
  15.  help here >> tbhighmark.Text = max Value;  
  16.  help here >> tbCourseAvg.Text = tbCourseAvg value;  
  17. }
  18. connection.Close();

Answers (12)