Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Text

Namespace SQLNameSpace
  Public Class SQLClass
   	Private ls_sql as string
  	Private ls_ConnStr as string
  
 	Public Sub New()
 		MyBase.New()
  		ls_sql = ""
  		ls_ConnStr = ""
  	End Sub
   	  	
  	Public Property SQL as string 
   		Get
  			Return ls_sql
   		End Get
   		Set
  			ls_sql = value
  
  		End Set
  	 End Property	
    
  	 Public Property ConnStr as string 
   		Get
  			Return ls_ConnStr 
   		End Get
   		Set
  			ls_ConnStr  = value
   		End Set
  	 End Property
   	
   	Public Function Populate() As DataView
  	    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
        End Function
   	
   	Public Function  test() as string
	   	Dim SB As StringBuilder
	   	SB = New StringBuilder(ls_sql)
	   	SB = SB.Append("..returned from function test")
	   	test = SB.ToString()
	End Function
   	
   
   	Function RunSql(vsql as string) as String
		Dim Message as string
		try
						
			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
End Namespace

