Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How I can convert code in submit button code to a WebMethod in WebService?

How I can convert code in submit button code to a WebMethod in WebService?

Scheduled Pinned Locked Moved ASP.NET
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saba02
    wrote on last edited by
    #1

    Hi all, How I can convert this code to a WebMethod in WebService? This code is here:

    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click

        Dim con As SqlConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("Articles").ConnectionString)
    
        Dim cmd As SqlCommand = New SqlCommand("SELECT Title, Content FROM tblArticle", con)
    
        con.Open()
    
        Accordion1.DataSource = cmd.ExecuteReader
        Accordion1.DataBind()
    
        con.Close()
    
    End Sub
    

    I try to convert this code to webmethod But I couldn't convert it to a WebMethod for WebService and use it in Application. How I can do this work? Please help me, Thank you

    Hoda

    A 1 Reply Last reply
    0
    • S Saba02

      Hi all, How I can convert this code to a WebMethod in WebService? This code is here:

      Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click

          Dim con As SqlConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("Articles").ConnectionString)
      
          Dim cmd As SqlCommand = New SqlCommand("SELECT Title, Content FROM tblArticle", con)
      
          con.Open()
      
          Accordion1.DataSource = cmd.ExecuteReader
          Accordion1.DataBind()
      
          con.Close()
      
      End Sub
      

      I try to convert this code to webmethod But I couldn't convert it to a WebMethod for WebService and use it in Application. How I can do this work? Please help me, Thank you

      Hoda

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Saba02 wrote:

      I try to convert this code to webmethod But I couldn't convert it to a WebMethod for WebService and use it in Application.

      How ? Adding [Web Methods] Attributes with a method does not convert it into a web service. You can create a separate web service for that, or you can add webservice in your current web application, which will add a webservice.cs file in your app code and do the rest thing by calling the WS.

      cheers, Abhijit CodeProject MVP

      S 1 Reply Last reply
      0
      • A Abhijit Jana

        Saba02 wrote:

        I try to convert this code to webmethod But I couldn't convert it to a WebMethod for WebService and use it in Application.

        How ? Adding [Web Methods] Attributes with a method does not convert it into a web service. You can create a separate web service for that, or you can add webservice in your current web application, which will add a webservice.cs file in your app code and do the rest thing by calling the WS.

        cheers, Abhijit CodeProject MVP

        S Offline
        S Offline
        Saba02
        wrote on last edited by
        #3

        Thank you, i have a web service for my project that i connect to data base with it. i don't have problem with creating web service,but i couldn't create a function for this code. How i can return result and use it in my application? when i use dataset i returned dataset: <webmethode()> Public Function getusers() as DataSet dim da as new sqldataadapter dim ds as new dataset . . . . da.fill(ds,"Tbl") return ds end Function and i use this code in my application: protected sub btn1_click(....................) dim ws as new localhost.service gridview1.datasource=ws.getusers() gridview1.databind() end sub now i have that code for submit button , only i don't know how i can write it in webservice instead of application? <WebMethod()> _ Public Function FillAccordion() as ????????? Dim cn As New SqlConnection Dim cls As New ClsGeneral cn.ConnectionString = cls.GetConnection cls = Nothing Dim cmd As SqlCommand = New SqlCommand("SELECT Title, Abstract FROM Articles", cn) cn.Open() cmd.ExecuteReader() cn.Close() return ???????? End Function i couldn't write that code using function in web service and use function in submit button!

        Hoda

        modified on Tuesday, April 14, 2009 8:47 AM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups