<%@ WebService Language="VB" Class="SQLService"%>
Imports System
Imports System.Web.Services
Imports System.Data
Imports System.Data.OleDb
Imports System.Text


Public Class SQLService: Inherits WebService
 <WebMethod()> Public  Function  TestFunction (vInput as Boolean) As String
	If (vInput = TRUE) Then
 	   TestFunction = "It is the truth..."	
	Else
	   TestFunction = "False!False!False"	
	End if 
   End Function

<WebMethod()> Public Function  add( a as integer, b as integer) as string
   add = cstr(a+b)
end function

<WebMethod()> Public Function  Populate(ConnStr as string, SQL as string) As DataSet
	Dim dv as DataView
	Dim i as integer
	Dim myConnection As OleDbConnection
	Dim myCommand    As OleDbDataAdapter
	Dim ds           As New DataSet
	myConnection = New OleDbConnection(ConnStr)    
	myCommand = New OleDbDataAdapter(SQL, myConnection)
	myCommand.Fill(ds, "vTable")
	'Populate = ds.Tables("vTable").DefaultView
	Populate = ds
End Function

 <WebMethod()>PUBLIC Function RunSql ( ConnStr as string, vsql as string) as String
	Dim Message as string
	try
		message = "Success"
		Dim myConnection As OleDbConnection
		myConnection = New OleDbConnection(ConnStr) 
		Dim mycommand As New OleDbCommand(vsql,myConnection)
		myConnection.Open()
		myCommand.ExecuteNonQuery()
		myConnection.Close()
	 Catch ex As OleDbException
		     Dim errItem   As OleDbError
		     Dim errString As String
		     For Each errItem In ex.Errors
			 errString += ex.Message + " "
		     Next
		     Message = "SQL 错误细节如下:<br/><br/>" & errString
	 catch myException as Exception
		     message = "出现异常: " + myException.ToString() 
	end try
	RunSql = message
End Function   
End Class

