Hi
Here is your code refactored. You did not return the final value as exactly said in the error message.
private bool SaveDetails()
{
if (string.IsNullOrEmpty(txt_Faccode.Text))
{
MessageBox.Show("Please enter the Faculty code", "Not Enter the details", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (string.IsNullOrEmpty(Txt_Facname.Text))
{
MessageBox.Show("Please enter the Faculty Name", "Not Enter the details", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (string.IsNullOrEmpty(txt_Hrs.Text))
{
MessageBox.Show("Please enter the allocated hours", "Not Enter the details", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
this.Cursor = Cursors.WaitCursor;
try
{
sql = "insert into Tb_SCH_Faculty_Details ([Faculty_Code], [Faculty_Name],[Allocated_Hours]) " + " values('" + txt_Faccode.Text + "','" + Txt_Facname.Text + "', " + txt_Hrs.Text + ")";
int temp = 0;
if (!int.TryParse(txt_Hrs.Text.Trim(), out temp))
{
MessageBox.Show("Enter Numbers only in allocated hours", "Characters Not Allowed", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
GFun.Error = "";
GFun.InsertAccessData(sql);
if (!string.IsNullOrEmpty(GFun.Error.ToString()))
{
MessageBox.Show(GFun.Error.ToString(), "Error");
this.Cursor = Cursors.Arrow;
return false;
}
GFun.OleDbCon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Cursor = Cursors.Arrow;
return false;
}
this.Cursor = Cursors.Arrow;
return true;
}
private void Btn_Save_Click(object sender, EventArgs e)
{
if (SaveDetails())
{
MessageBox.Show("Record Inserted Successfully", "Records Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Not Inserted Successfully", "Records Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Regards
Jegan