0

Here is my issue. I have a stored procedure that returns an output that is a bit. I am trying to view the Boolean value via the web service. The stored procedure totally works, but I can't seem to figure out how to display the needed value (which is a boolean).

The store procedure:

@CE_IN VARCHAR(2)
@return_OUT BIT OUTPUT
IF EXISTS(SELECT Ce FROM Table A WHERE @CE_IN = Ce)
BEGIN IF EXISTS(SELECT * FROM Table A)
set @return_OUT = 1
ELSE 
set @return_OUT = 1
END
ELSE set @return_OUT = 0

The following library class is what I use to call the stored procedure.

public Boolean ValidC(String VC) 
    {
            DbCommand dbCommand = db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "CE_IN", DbType.String, VC);
            db.AddOutParameter(dbCommand, "return_OUT", DbType.Boolean, 1);
            db.ExecuteNonQuery(dbCommand);

            return (Boolean)dbCommand.Parameters["@return_OUT"].Value;
    }

Once executed the procedure returns the Boolean value. (In theory)

Last piece of the puzzle is the web service call.

[WebMethod]
public bool Validation(string VC)
     {
         ValidC c = new ValidC(VC);
         if(c. == true)
             return true;

         else
             return false;

     } 
5
  • 6
    You can't figure out "how to make get the to the be server browser." That is the most word-salady thing I've seen in a SO question in a long time... p.s. J. Ballard? The guy from B613? Commented Apr 15, 2014 at 16:03
  • Correction. I can't figure out how to get the value to the web server. My mistake. Commented Apr 15, 2014 at 16:12
  • "but I can't seem to figure out how to display the needed value"...How are you trying to display it? Client side, in the browser I assume? How does your client-side look like? Commented Apr 15, 2014 at 16:22
  • RealityDysfunction on the client side I would like to display it as a JSON. The stored procedure executes and gives me the 1 or a 0 bit in MSSQL. Code that calls the stored procedure gets the parameter but the web service method doen't work correctly. Commented Apr 15, 2014 at 16:29
  • Ilya Nemtsev is actually right. You can use the following site as a reference for doing so. brian.dobberteen.com/code/jquery_ajax_custom_validator Commented Apr 23, 2014 at 15:25

1 Answer 1

1

The easiest way to do this is using jQuery on the client side.

sendData = new Object();
sendData.validateThis = "SomeDataToValidateGoesHere";
    $.ajax({
            url: "urlOfWebMethodOrSomething/ValidateField",
            type: 'POST',
            data: JSON.stringify(sendData),
            contentType: "application/json",
            dataType: 'json',
            success: function (resultObj) {
                      if (resultObj.valid == true) 
                          console.log("Yay I'm valid");
                      else
                          console.log("This sucks!");
                            },
            error: function () {
                      console.log('An error has occured...');
                            }
                        });

On server-side you can use a model like this...

public class ValidateResponse
{
    public bool valid { get; set; }
    public String ResponseMsg { get; set; }
}

Then respond in the WebMethod like so:

    public virtual String ValidateField(String validateThis)
    {
    ValidateResponse valResp = SomeValidationMethod(validateThis);
    return Json(valResp);
    }

Hope that gets you started...

Sign up to request clarification or add additional context in comments.

1 Comment

I hope so too, Thanks. I'm going to see what I can get done with what you have up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.