How I can convert code in submit button code to a WebMethod in WebService?
-
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
-
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
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
-
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
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