Locations of visitors to this page


Sql Endpoint and DataGridView

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sql Endpoint and DataGridView

Sql Endpoint and DataGridView

SQL Server 2005 allows you to create webservices for accessing the data in a database.  These webservices are call SQL End Points.  Lets start by creating a stored procedure to get the contact name and there titles for all the customers in the northwind database.  

Create PROCEDURE [dbo].[GetContacts]
AS
BEGIN
    SET NOCOUNT ON;

    SELECT [ContactName],[ContactTitle] FROM Customers ORDER BY [ContactName];
END

Now we can create the end point.  Note for this example I am using port 88 for the end point to prevent errors if you have IIS installed.

CREATE ENDPOINT NW_Contacts
    STATE = Started
AS HTTP
    (
        PATH = '/Contacts',
        AUTHENTICATION = (INTEGRATED),
        PORTS = (CLEAR),
CLEAR_PORT = 88,
        SITE = '*'
    )
FOR SOAP
    (
        WEBMETHOD 'GetContacts'
            (NAME = 'Northwind.dbo.GetContacts'),
        WSDL = DEFAULT,
        DATABASE = 'Northwind',
        NAMESPACE = DEFAULT
    )


Now we need to create a windows forms application.  I called the app EndPointTest.  On the form add a datagridview and set its dock property to fill.
Then add a web reference to the app.  For the url use http://localhost:88/contacts?WSDL.  For the name I used ContactEndPoint.
Here is some sample code for filling the datagridview with data from the end point

Imports System.Net

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ws As New ContactEndPoint.NW_Contacts

        ws.Credentials = CredentialCache.DefaultCredentials

        Dim ds As DataSet = TryCast(ws.GetContacts(0), DataSet)
        DataGridView1.DataSource = ds.Tables(0)

    End Sub
End Class

Currently rated 2.7 by 3 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: DataGridView | Sql
Posted by Ken Tucker on Wednesday, June 27, 2007 1:12 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments are closed