how to put conditions for this code

Mar 26 2010 8:52 AM

the total code will be in same button control if all these if ,else and foreach conditions are satisfide i want to enter the data into database how to put condition for that
 
if (txtcomutedleaves.Text == string.Empty)
lblcomutedleaves.Visible =
true;
else
lblcomutedleaves.Hide();
if (txtmaternity.Text == string.Empty)
lblmaternity.Visible =
true;
else
lblmaternity.Hide();
if (txtmiscarriage.Text == string.Empty)
lblmaxcarriage.Visible =
true;
else
lblmaxcarriage.Hide();
if (txtrhs.Text == string.Empty)
lblmaxrhs.Visible =
true;
else
lblmaxrhs.Hide();
foreach (Control c in this.Controls)
{
if (c is TextBox)
{
try
{
int.Parse(c.Text);

}
catch
{
c.Text=
"Enter Int";
}
}
}
 
/// if above conditions are satisfied then only the bellow code should be executed how to put the condition for this ,please tell me
 
 
 
 

SqlConnection con = new SqlConnection();
con.ConnectionString =
ConfigurationSettings.AppSettings["conn"].ToString();
con.Open();
string strsql = "insert into maxleaves values('" + txtcls.Text + "','" + txthpls.Text + "','" + txtels.Text + "','" + txtpaternity.Text + "','" + txtsleave.Text + "','" + txtcomutedleaves.Text + "','" + txtmaternity.Text + "','" + txtmiscarriage.Text + "','" + txtrhs.Text + "')";
SqlCommand cmd = new SqlCommand(strsql, con);
cmd.ExecuteNonQuery();
con.Close();

Answers (3)