2
Answers

validation for user input -beginner-

karabela steel

karabela steel

16y
3.5k
1

im a beginner to c#. i have the following question.

i want to add a validation for user input such as making sure the year of the car is not greater than the current year +2. where can i add this validation user input.

my main.cs code is like this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CarTracker

{

public partial class Main : Form

{

public Main()

{

InitializeComponent();

}

private void listingBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

this.Validate();
this.listingBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.carTrackerDataSet);

}

private void Form1_Load(object sender, EventArgs e)

{

// TODO: This line of code loads data into the 'carTrackerDataSet.CarType' table. You can move, or remove it, as needed.
this.carTypeTableAdapter.Fill(this.carTrackerDataSet.CarType);
// TODO: This line of code loads data into the 'carTrackerDataSet.Make' table. You can move, or remove it, as needed.
this.makeTableAdapter.Fill(this.carTrackerDataSet.Make);
// TODO: This line of code loads data into the 'carTrackerDataSet.Color' table. You can move, or remove it, as needed.
this.colorTableAdapter.Fill(this.carTrackerDataSet.Color);
// TODO: This line of code loads data into the 'carTrackerDataSet.Listing' table. You can move, or remove it, as needed.
this.listingTableAdapter.Fill(this.carTrackerDataSet.Listing);

}

private void fillByColorNameToolStripButton_Click(object sender, EventArgs e)

{

try

{

this.listingTableAdapter.FillByColorName(this.carTrackerDataSet.Listing, colornameToolStripTextBox.Text);

}

catch (System.Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

}

private void fillByCarTypeNameToolStripButton_Click(object sender, EventArgs e)

{

try

{

this.listingTableAdapter.FillByCarTypeName(this.carTrackerDataSet.Listing, cartypenameToolStripTextBox.Text);

}

catch (System.Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

}

private void fillByMakeNameToolStripButton_Click(object sender, EventArgs e)

{

try

{

this.listingTableAdapter.FillByMakeName(this.carTrackerDataSet.Listing, makenameToolStripTextBox.Text);

}

catch (System.Exception ex)

{

System.Windows.Forms.MessageBox.Show(ex.Message);

}

}

}

}

Answers (2)