Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
<WebMethod()> _
Public Function HelloWorld() As String
Dim strConnString As String
strConnString = "Server=localhost\SQL2008;UID=sa;PASSWORD=sqlserver2008;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New SqlConnection(strConnString)
objConn.Open()
If objConn.State = ConnectionState.Open Then
Return "SQL Server Connected"
Else
Return "SQL Server Connect Failed"
End If
End Function
End Class
ยังไงขอรบกวนด้วยนะครับ ^^
Tag : .NET, Ms SQL Server 2008, WebService, VB.NET
มันก็ Return ปกติน่ะครับ เพียงแต่ผ่าน Web Service ครับ
Code (VB.NET)
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
<WebMethod()> _
Public Function HelloWorld() As DataSet
Dim ds As New DataSet
Dim strConnString, strSQL As String
strConnString = "Server=localhost\SQL2008;UID=sa;PASSWORD=sqlserver2008;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
End Function
End Class
''' INSERT UPDATE DELETE --> หลายค่า -- โปรแกรมสำหรับฝั่ง WEB SERVICE ----------
<WebMethod()> _
Public Function Exc_DataSet(ByVal dataSet As DataSet) As Boolean
Dim dr As DataRow
Try
__BeginTrans()
For Each dr In dataSet.Tables(0).Rows
sql = dr("TABLE1_") ''''HEADER_ --> Name head data set from Client 1 ROW
__TransExeSQL(sql)
Next
Trans.Commit()
'Return ("Complate !!!! ")
Return True
Catch ex As Exception
Trans.Rollback()
Console.WriteLine(Err.Description)
' Return ("Can't Complate !!!! " & Err.Description)
Return False
Finally
If objcon.State <> ConnectionState.Closed Then
objcon.Close()
End If
End Try
End Function