Database Query Within WebServices

Submitted by:J Kamy81

Date added:06 July, 2017

Category:ASP

Asp.Net code snippet for Database Query Within WebServices

Tags: database query

Code Snippet:

Database Query Within WebServices

<%@ WebService Language="vb" Class="articleListing" %>
Imports System.Web.Services
Imports System.Data
Imports System.Data.SQLClient


Public Class articleListing

<WebMethod()> _
Public Function DisplayAllArticles() As DataSet

Dim MyConn as New SQLConnection("server=localhost;User id=sa;password=;database=ikon")
Dim ds as DataSet=New DataSet()
Dim cmd2 As SQLDataAdapter = New SQLDataAdapter("select Top 10 articleID, headline, summary from articles order by articleDate desc", MyConn)
cmd2.Fill(ds, "articles")
return ds
end function


<WebMethod()> _
Public Function readArticles(ID as integer) As DataSet

Dim MyConn as New SQLConnection("server=localhost;User id=sa;password=;database=ikon")
Dim ds as DataSet=New DataSet()
Dim cmd2 As SQLDataAdapter = New SQLDataAdapter("select * from articles Where articleID = '"& ID &"'", MyConn)
cmd2.Fill(ds, "articles")
return ds
end function
end class
 
 

Comments