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

    Validate record exists and print message on page

    I am passing EmpID from 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#( code behind)
    In stored procedure and print message on the form.

  • #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.

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

  • Sign In to post your comments