You must Sign In to post a response.
  • Category: SQL Server

    Validate record exists and print message on page

    Hi,
    I am passing EmpID from asp.net page (textbox) and I have a stored proc to get the EmpName (by passing EmpID).
    I want to validate and print message on web page if the EmpID is not found in the table.
    Could you please suggest me how to do it in c#(asp.net code behind)
    Or
    In stored procedure and print message on the form.

    Thanks...
  • #762538
    Hello Pramod,

    Refer the below code :

    string message = String.Empty;
    SqlCommand cmd = new SqlCommand("sp_userinformation", con);
    cmd.Parameters.Add("@Output", SqlDbType.Char, 500);
    cmd.Parameters["@Output "].Direction = ParameterDirection.Output;
    message = (string) cmd.Parameters["@Output "].Value;

    if(message == "" or message == null)
    {
    Response.Write("<script>alert('" + Server.HtmlEncode("Record does not exist") + "')</script>");
    }


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments