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