else problem in asp.net

Posted by Dn2010 under ASP.NET on 4/5/2012 | Points: 10 | Views : 701 | Status : [Member] | Replies : 1
hi friends,

In if condition,

it checks only else part in runtime,

CommandText = "select * from empOrder By calldate desc limit 20 WHERE calldate > '" + Label1.Text + "' Order By calldate desc limit 20";


please correct this code.


OdbcConnection myConnection = new OdbcConnection(ConnectionString);

string CommandText = string.Empty;

if(Label1.Text == "" || Label1.Text == null)
{
CommandText = "select * from emp Order By calldate desc limit 20";
}
else
{
CommandText = "select * from emp Order By calldate desc limit 20 WHERE calldate > '" + Label1.Text + "' Order By calldate desc limit 20";
}
OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);

myConnection.Open();

GridView1.DataSource = myCommand.ExecuteReader();
GridView1.DataBind();

myConnection.Close();
thanks.




Responses

Posted by: Naraayanan on: 4/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
try this way,

f(Label1.Text != "" || Label1.Text != null)

{
CommandText = "select * from emp Order By calldate desc limit 20 WHERE calldate > '" + Label1.Text + "' Order By calldate desc limit 20";

}
else
{
CommandText = "select * from emp Order By calldate desc limit 20";
}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response