Question: C# Lab: We were assigned the lab to connect database with Windows form application and create some methods to perform certain tasks. Below is my

C# Lab:

We were assigned the lab to connect database with Windows form application and create some methods to perform certain tasks. Below is my code( but its not working , when i run the code , an error occurs in first line of LowestScore(() method(I have written it in bold ).The error that occurs is :An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll.

the purpose of the method is to compare all the three scores and display the lowest one in the new text box .

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;

namespace StudentTestScores_DetailView { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void testsBindingNavigatorSaveItem_Click(object sender, EventArgs e) { this.Validate(); this.testsBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.studentScoresDataSet);

}

private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'studentScoresDataSet.Tests' table. You can move, or remove it, as needed. this.testsTableAdapter.Fill(this.studentScoresDataSet.Tests); LowestScore();

} private void LowestScore() { double lowestScore = Convert.ToDouble(textBox1.Text); // textBox1.Text = lowestScore.ToString(); double average = Convert.ToDouble(textBox2.Text);

if (Convert.ToDouble(test1TextBox) < Convert.ToDouble(test2TextBox) && Convert.ToDouble(test1TextBox) < Convert.ToDouble(test3TextBox)) { lowestScore = Convert.ToDouble(test1TextBox); }

else if (Convert.ToDouble(test2TextBox) < Convert.ToDouble(test3TextBox) && Convert.ToDouble(test2TextBox) < Convert.ToDouble(test1TextBox)) { lowestScore = Convert.ToDouble(test2TextBox); }

else if (Convert.ToDouble(test3TextBox) < Convert.ToDouble(test1TextBox) && Convert.ToDouble(test3TextBox) < Convert.ToDouble(test2TextBox)) {

lowestScore = Convert.ToDouble(test3TextBox); } } private void bindingNavigatorPositionItem_Click(object sender, EventArgs e)

{ LowestScore(); }

} }

I cant figure out what am i doing wrong and need help with that.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!