sql server 2008 - How to check if the value is not null and if not then the value should be displayed in Textbox in ASP.NET -
this code
sqlconnection con = new sqlconnection(cs); con.open(); string query = "select name t_identities branchid = '" + branchidtext.text + "' , accountid = '" + accountidtext.text + "'"; sqlcommand cmd = new sqlcommand(query, con); string value = cmd.executescalar().tostring(); if (value != null) { nametext.text = value.tostring(); } else { nametext.text = "no records found"; } }
if query returs null textbox should return no records found or else should display name generated query in text box. please help.
probably getting error in line
string value = cmd.executescalar().tostring();
as trying convert null value string. better use convert.tostring(cmd.executescalar())
handle case.
your if/else block ok
Comments
Post a Comment