c# - Search query returns none -
i have stored procedure in sql searches employee details. when finds something,it returns , displays data in gridview. how can handle if did not return anything? when 'no record found'?
using (sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["dbreader"].connectionstring)) { using (sqlcommand com = new sqlcommand("[reader].[usp_searchuser]", con)) { com.commandtype = commandtype.storedprocedure; com.parameters.add("@empid", sqldbtype.int).value = this.empid; con.open(); int result = com.executenonquery(); if (result == 0) { this.norecord = "no record found"; } else { sqldataadapter da = new sqldataadapter(com); dataset ds = new dataset(); da.fill(ds); search.datasource = ds; search.databind(); } } }
did not exact question? want gridview property when there no data show no records found i.e. emptydatatext="no records found" e.g.
<asp:gridview id="gridview1" runat="server" emptydatatext="no records found"> <columns> <asp:boundfield datafield="empid" headertext="employee id"/> <asp:boundfield datafield="empname" headertext="employee name"/> </columns> </asp:gridview>
Comments
Post a Comment