Imports System.Data.SqlClientNamespace ReadData Public Class Database Private con As SqlClient.SqlConnection Private Sub Open () 'Open Database Connectivity If con Is Nothing Then con = New SqlConnection (ConfigurationSettings.AppSettings ( "ConnectionString")) End If If con.State = System.data.connectionsState.closed the Con. Open () endiff
End Sub Public Sub Close () Close IF NOT Con Is Nothing Then Con. Close () end if End Sub
Public Sub Dispose () confirms if the connection is closed if not con lyning kil.dispose () Con = Nothing end if End Sub
Public Function MakeParam (ByVal ParamName As String, ByVal DbType As SqlDbType, ByVal Size As Int32, ByVal Direction As ParameterDirection, ByVal Value As Object) As SqlParameter Dim param As SqlParameter
IF size> 0 Then param = new Sqlparameter (paramname, dbtype, size) else param = new sqlparameter (paramname, dbtype) endiff
PARAM.DIRECTION = Direction if not (direction = parameterdirection.output and value = nothing) Then param.value = value Endiff
Return Param End Function
Public Function MakeReturnParam (ByVal ParamName As String, ByVal DbType As SqlDbType, ByVal Size As Integer) As SqlParameter Return MakeParam (ParamName, DbType, Size, ParameterDirection.ReturnValue, Nothing) End Function
Public Function MakeOutParam (ByVal ParamName As String, ByVal DbType As SqlDbType, ByVal Size As Integer) As SqlParameter Return MakeParam (ParamName, DbType, Size, ParameterDirection.Output, Nothing) End FunctionPublic Function MakeInParam (ByVal ParamName As String, ByVal DbType As SqlDbType , Byval size as integer, byval value as object) AS SQLParameter Return Makeparam (paramname, dbtype, size, parameterdirection.input, value) end function
Private function createcommand (Byval prams () as sqlparameter) AS SQLCOMMAND 'confirms open connection open ()
DIM CMD As Sqlcommand = New Sqlcommand (Procname, Con) cmd.commandtype = CommandType.StoredProcedure
'Incorporation of parameters into stored procedure if not prams is nothing the dim parameter as sqlparameter for Each Parameter In Prams cmd.parameters.add (parameter) Next End End End End
'Join the parameter cmd.Parameters.Add (New Sqlparameter ("ReturnValue", SqldbType.int, 4, ParameterDirection.ReturnValue, False, 0, 0, String.empty, DataRowVersion.default, Nothing)
Return cmd end function
Public Function RunProc (ByVal procName As String) As Integer Dim cmd As SqlCommand = CreateCommand (procName, Nothing) cmd.ExecuteNonQuery () Me.Close () Return CType (cmd.Parameters ( "ReturnValue"). Value, Integer) End Function
'/
End Sub
'/
End Namespace