no records message in Label2.text in asp.net

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

i fill the record in Label from database.
how to no records message in Label2.text
i want to if no records in database or empty, show the message in Label2.



cmd.Connection = con;
cmd.CommandText = "select max(vdate) from emp";

Label2.Text = Convert.ToString(cmd.ExecuteScalar());

if(Label2.Text=="")
Label2.Text = "No Records Found";
con.Close();

please give the correct the code.


thanks.




Responses

Posted by: Sabarimahesh on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down

string str=cmd.ExecuteScalar().ToString()
Label2.Text = str;

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
cmd.Connection = con;
cmd.CommandText = "select max(vdate) from emp";

Label2.Text = Convert.ToString(cmd.ExecuteScalar());

if(Label2.Text!=Null)
Label2.Text = "No Records Found";
con.Close();

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Posted by: Sabarimahesh on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
Perfect.Chourasia@Gmail.Com

Good


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Posted by: Ajay.Kalol on: 4/5/2012 [Member] Starter | Points: 25

Up
0
Down
Here is Other Optimised Way..

cmd.Connection = con;
cmd.CommandText = "SELECT ISNULL(max(vdate),'No Record Found') from emp";
Label2.Text = Convert.ToString(cmd.ExecuteScalar());
con.Close();

Ajay
ajaypatelfromsanthal.blogspot.in

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

Posted by: Self-Innovator on: 4/5/2012 [Member] Bronze | Points: 25

Up
0
Down
Sqlconn cnn=new Sqlconn(Conn)--get it From Web.ConfigFile or Some where

Sqlcommand cmd=new SqlCommand("SpGetValues",cnn);
Sqldatasdapte ada=new SqlDataAdapter(cmd);
Dataset ds=new Dataset();
ada.Fill(ds);
if(ds.Tables[0].Rows.Count==0)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<script language='javascript'>alert('No Records Found')</script>");
}
else
{
Label1.Text=ds.Tables[o].Rows[o]["Values"].Tostring();
}


Join Hands Change lives
Thanks & Regards
Straight Edge Society

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

Posted by: Sabarimahesh on: 4/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Self-Innovator
pLEASE pOST tHE sP................
SpGetValues

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

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

Login to post response