how to pass a value in this webservice?

Discussion in 'ASP .Net Web Services' started by Bob, Dec 24, 2006.

  1. Bob

    Bob Guest

    Hi,

    I made a webservice for fetching data from a database. It works good.
    Now i would like to add a parameter to the sql command. The user should
    enter a value (pcnr) before the
    data is fetched. I tried to add a texbox but it doesn't work.
    How can i do that?
    Thanks
    Bob

    My code:
    ......
    <WebMethod()> _
    Public Function pcinfo() As DataSet
    Dim oConnection As OleDbConnection
    Dim pcnr As Integer
    Dim d As OleDbDataAdapter
    oConnection = New OleDbConnection()
    Dim sql As String
    Dim ds As New DataSet

    Dim tb As New TextBox
    pcnr= Convert.ToInt16(tb.Text)

    sql = "SELECT * from pc where pcnr=" & pcnr & ";"
    Dim sConnectionString As String
    sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source
    = c:\mytable.mdb"
    d = New OleDbDataAdapter(sql, sConnectionString)
    d.Fill(ds)
    Return ds
    End Function
    .....
     
    Bob, Dec 24, 2006
    #1
    1. Advertising

  2. Bob

    Bob Guest

    I found it.
    pcinfo(ByVal pcnr As String)

    "Bob" <.> schreef in bericht news:...
    > Hi,
    >
    > I made a webservice for fetching data from a database. It works good.
    > Now i would like to add a parameter to the sql command. The user should
    > enter a value (pcnr) before the
    > data is fetched. I tried to add a texbox but it doesn't work.
    > How can i do that?
    > Thanks
    > Bob
    >
    > My code:
    > .....
    > <WebMethod()> _
    > Public Function pcinfo() As DataSet
    > Dim oConnection As OleDbConnection
    > Dim pcnr As Integer
    > Dim d As OleDbDataAdapter
    > oConnection = New OleDbConnection()
    > Dim sql As String
    > Dim ds As New DataSet
    >
    > Dim tb As New TextBox
    > pcnr= Convert.ToInt16(tb.Text)
    >
    > sql = "SELECT * from pc where pcnr=" & pcnr & ";"
    > Dim sConnectionString As String
    > sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data
    > Source = c:\mytable.mdb"
    > d = New OleDbDataAdapter(sql, sConnectionString)
    > d.Fill(ds)
    > Return ds
    > End Function
    > ....
    >
     
    Bob, Dec 25, 2006
    #2
    1. Advertising

  3. Bob

    RYoung Guest

    Glad you found it. Keep in mind that the Web service has no clue as to what
    client is using it. I say that because from your question I gather the
    client is a .NET app, by the use of TextBox. A service has no visual
    interface, unless the service host is a GUI application, and therefore
    shouldn't be concerned with UI controls.

    Your service would want to stick with dealing with the primitives types
    (int, string, double, bool, etc), or with serializable complex types built
    from primitive types.

    Ron

    "Bob" <.> wrote in message news:...
    >I found it.
    > pcinfo(ByVal pcnr As String)
    >
    > "Bob" <.> schreef in bericht news:...
    >> Hi,
    >>
    >> I made a webservice for fetching data from a database. It works good.
    >> Now i would like to add a parameter to the sql command. The user should
    >> enter a value (pcnr) before the
    >> data is fetched. I tried to add a texbox but it doesn't work.
    >> How can i do that?
    >> Thanks
    >> Bob
    >>
    >> My code:
    >> .....
    >> <WebMethod()> _
    >> Public Function pcinfo() As DataSet
    >> Dim oConnection As OleDbConnection
    >> Dim pcnr As Integer
    >> Dim d As OleDbDataAdapter
    >> oConnection = New OleDbConnection()
    >> Dim sql As String
    >> Dim ds As New DataSet
    >>
    >> Dim tb As New TextBox
    >> pcnr= Convert.ToInt16(tb.Text)
    >>
    >> sql = "SELECT * from pc where pcnr=" & pcnr & ";"
    >> Dim sConnectionString As String
    >> sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data
    >> Source = c:\mytable.mdb"
    >> d = New OleDbDataAdapter(sql, sConnectionString)
    >> d.Fill(ds)
    >> Return ds
    >> End Function
    >> ....
    >>

    >
    >
     
    RYoung, Jan 13, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry
    Replies:
    20
    Views:
    8,007
    Roedy Green
    Sep 9, 2005
  2. venkatagmail
    Replies:
    11
    Views:
    709
    James Kanze
    Oct 3, 2007
  3. Vols
    Replies:
    3
    Views:
    390
    Ian Collins
    Apr 28, 2008
  4. Tricky
    Replies:
    0
    Views:
    599
    Tricky
    Mar 19, 2009
  5. Tricky
    Replies:
    0
    Views:
    1,045
    Tricky
    Mar 19, 2009
Loading...

Share This Page