Hi guys,
I have a series of validation checks that i need to complete in order to be able to save a record. I wanted to do this in the way below.
public override void SaveRecord()
{
NameCheck();
PostcodeCheck();
SaveRecord();
}
As you can tell, even if the checks are not met, it still goes through the next method. However, i want the method to stop as soon as it does not fulfill the validation check.
The check in the 'NameCheck' method is if the user does not input a name, then the program displays an error box and does not save the record. The 'PostcodeCheck' is there to ensure that there are no duplicates of the same postcode.
Is this possible?
Kindest Regards,
Rahul Patel
Loading
Satyapriya NayakPosted Dec 18, 2012, 10:29 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Registration_in_Msaccess
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
public Form1()
{
InitializeComponent();
}
private void btn_insert_Click(object sender, EventArgs e)
{
if (txtUserName.Text == "" || txtUserAddress.Text == "")
{
MessageBox.Show("Please insert the values");
}
else
{
namecheck();
}
}
private void namecheck()
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select count(*)from employee where ename='" + txtUserName.Text + "'";
com = new OleDbCommand(str, con);
int count = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (count > 0)
{
lblMessage.Text = "Sorry! you can't take this username";
}
else
{
lblMessage.Text = "You can take this username";
con.Open();
str = "insert into employee(ename,eaddress) values('" + txtUserName.Text + "','" + txtUserAddress.Text + "')";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
}
}
}
}
Thanks
If this post helps you mark it as answer