ARTICLE

Countries/Cities of US States (Webservice/ADO.NET Demo)

Posted by Arun Nair Articles | ADO.NET in VB.NET May 17, 2004
Here in this example, I'll demonstrate the use of ADO.NET through a webservice and make you realise that its not a monster replacement to ADO 2.5.
 
Reader Level:

Introduction

Here in this example, I'll demonstrate the use of ADO.NET through a web service and make you realize that its not a monster replacement to ADO 2.5 after all.... though it is monstrous in terms of its features and the power it exudes :). I have included a database along with the zip called LIS (Location Information Services), which has two tables viz. statemaster (all states in the US) and countymaster (counties and cities for a particular state). This web service accepts the abbreviation of a US state and returns the counties/cities within that state.

Note: You have to create a DSN called LIS, mapping it to the MS-Access db provided along as zip along with article.

Source Code

Imports System.ComponentModel
Imports System.Configuration
Imports System.Web.Services
Imports System.Diagnostics
Imports System.Data
Imports System.Data.SQL
Imports System.Data.ADO
Public Class Service1
Inherits System.Web.Services.WebService
Public Function <WebMethod()>
getCounties(
ByVal stateAbr As String) As
DataSet
Dim strConnString As String
strconnstring = "DSN=LIS"
'Create an ADOConnection instance
Dim objConn As ADOConnection
objconn =
New ADOConnection
'Set the ADOCOnnection object's connection string property
objconn.ConnectionString = strconnstring
objconn.Open()
'Create a SQL string
Dim strSQL As String = "select countyname,gslid from countymaster where stateid=(select stateid from statemaster where abbr='" & stateAbr & "')"
'Create an instance of the ADODatasetcommand and Dataset objects
Dim objDSCommand As ADODataSetCommand
Dim objDataset As DataSet
objdataset =
New DataSet
objdscommand =
New ADODataSetCommand(strsql, objconn)
objdscommand.FillDataSet(objdataset, "Counties")
Return objDataset
objconn.Close()
objconn =
Nothing
End Function
Public Sub New()
MyBase.New()
InitializeComponent()
'Add your own initialization code after the InitializeComponent call
End Sub
End
Class

share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor