none
i am sending data from jquery to wcf service and that data i want to post in where clause of sql query in wcf??? RRS feed

  • Question

  • JQUERY POST 

    function xxxxxxx1(tx)
            {
                 $.support.corps = true;
                  $.ajax({
                      type: 'POST', 
                      crossDomain: true,
                      url: 'xxxxxxxxx/Service1.svc/GetMachines1/18',
                      contentType: "application/javascript",
                      dataType: "json",
                      processData: false,
                      async : false,
                      success:alert (response);

                      },
                      error: function ServiceFailed(xhr, textStatus, errorThrown)// When Service call fails
                      {
                          alert(JSON.stringify(errorThrown));
                          alert("module data error");
                      }
                  });

            }

    ISERVICE

     <OperationContract()> _
         <WebInvoke(Method:="POST",
                      BodyStyle:=WebMessageBodyStyle.Wrapped,
                      ResponseFormat:=WebMessageFormat.Json,
                      UriTemplate:="GetMachines1/{value}")>
        Function GetMachines1(ByVal value As String) As List(Of Common.DataContract.Machine)

    SERVICE1.svc

    Public Function GetMachines1(ByVal value As String) As List(Of Common.DataContract.Machine) Implements IService1.GetMachines1
            Using oDL As New Datalogic.Class1
                Return oDL.GetMachineList
            End Using
        End Function

               

        Public Function GetMachineList() As List(Of Common.DataContract.Machine)
            Dim oConn As New xxxxx
            Dim machines As New List(Of Common.DataContract.Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone where k_paikka = xx"

    I WANT THAT VALUE SEND FROM JQUERY PARAMETER WHICH IS 18 SHOULD BE PLACED INSTEAD OF XX, HOW CAN I DO THAT
            Try
                oConn.OpenDB()
                Dim reader = oConn.SelectQueryIntoReader(strSql)



                Return machines

            Catch ex As Exception
                Throw New System.Exception(ex.Message)
            Finally
                oConn.CloseDB()
            End Try

        End Function

    Thursday, October 16, 2014 11:11 AM

Answers

  • Try following code

    Public Function GetMachines1(ByVal value As String) As List(Of Common.DataContract.Machine) Implements IService1.GetMachines1
            'Using oDL As New Datalogic.Class1
                Return oDL.GetMachineList
            'End Using
        End Function
    
               
        Public Function GetMachineList(ByVal value as String) As List(Of Common.DataContract.Machine)
            Dim oConn As New xxxxx
            Dim machines As New List(Of Common.DataContract.Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone where k_paikka = '" & value & '"
    
           


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Thursday, October 16, 2014 4:41 PM

All replies

  • Try following code

    Public Function GetMachines1(ByVal value As String) As List(Of Common.DataContract.Machine) Implements IService1.GetMachines1
            'Using oDL As New Datalogic.Class1
                Return oDL.GetMachineList
            'End Using
        End Function
    
               
        Public Function GetMachineList(ByVal value as String) As List(Of Common.DataContract.Machine)
            Dim oConn As New xxxxx
            Dim machines As New List(Of Common.DataContract.Machine)()
            Dim strSql As String = "SELECT k_koneno AS ma_machineid,k_paikka AS ma_placenumber,k_malli AS ma_model,k_tyyppi AS ma_type,k_versio AS ma_version FROM kone where k_paikka = '" & value & '"
    
           


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Thursday, October 16, 2014 4:41 PM
  • i am trying to place integer in the form of string.

    but query is getting the value and settting the column equal to myvalue. It is not checking it just replacing the original value with my value.

    I want to check the value?

    should i convert string into integer or do something else?

    Thanks

    Monday, October 20, 2014 1:44 PM
  • thanks got it.
    Tuesday, October 21, 2014 10:58 AM