I DEVELOP A SOFTWARE ON VISUAL STUDIO (C #) "EMPLOYEE INFROMATION SYSTEM",
WHEN I ENTERED A RECORD IN SOFTWARE, IT ADDED,
BUT WHEN I ADDED A RECORD HAVING EMPTY FIELDS
IT SHOWS RECORD DOES NOT ADDED BECAUSE FIELDS ARE EMPTY,
BUT IN DATA BASE RECORD WILL SAVE HAVING EMPTY FIELDS, WHY?
ANY BUDY HELP ME...!
THE CODE IS THAT:
==>
private void button1_Click(object sender, EventArgs e)
{
try
{
Department obj = new Department();
obj.DeptName = textBox1.Text;
obj.Description = textBox2.Text;
DepartmentDAL obj2 = new DepartmentDAL();
obj2.addDepartment(obj);
if (textBox1.Text != "" && textBox2.Text != "")
{
MessageBox.Show("Record Saved Successfully !", "Employee Information System");
clear();
}
else { MessageBox.Show("Error : Field's Empty \n\nEnter The Record To Save !", "Employee Information System"); }
}
catch { MessageBox.Show("Error : Field's Empty \n\nEnter The Record To Save !", "Employee Information System"); }
}
Rahul PrajapatPosted Jun 27, 2015, 8:20 PM
Khan Abrar AhmedPosted Jun 28, 2015, 5:23 AM
Munesh SharmaPosted Jun 28, 2015, 3:46 AM
Narasimha Reddy ChennupalliPosted Jun 27, 2015, 2:33 PM
First you need to check empty fields, if fields are not empty then you need to add data in to database. As like below
if (textBox1.Text != "" && textBox2.Text != "")
{
Department obj = new Department();
obj.DeptName = textBox1.Text;
obj.Description = textBox2.Text;
DepartmentDAL obj2 = new DepartmentDAL();
obj2.addDepartment(obj);
MessageBox.Show("Record Saved Successfully !", "Employee Information System");
clear();
}