A Wrapper Class for DML Statements Using Visual Basic.NET - The beginning of the class
(Page 2 of 7 )
Let us first go through the following code:
PublicClass DMLLib
...
Private m_SQL As String = ""
Private m_dbObject As Object = Nothing 'this should be either
'WebLib' or 'WinLib' objects
Private m_ColNameList As String = ""
Private m_ColValList As String = ""
Private m_CommandType As CommandType
'only for storing files directly in database
Private m_FileColNames() As String = Nothing 'to hold all
column names to which files are to be uploaded
Private m_FileByteArrays() As Object = Nothing 'the content
of each file to be uploaded..
Public Sub New(ByVal DMLCommandType As CommandType, ByRef
dbObject As Object) 'dbObject should be either 'WebLib' or
'WinLib' objects
If dbObject Is Nothing Then
Throw New Exception("DBLib Object is currently
nothing")
End If
m_dbObject = dbObject
m_CommandType = DMLCommandType
Select Case DMLCommandType
Case CommandType.Insert
m_SQL = "INSERT INTO "
Case CommandType.Update
m_SQL = "UPDATE "
End Select
End Sub
The above code contains the constructor, which accepts two parameters. The first is "CommandType" and the second is the "database" object. Based on the command type, I initially started with the command itself.
To provide the table name, I created the following property:
PublicWriteOnly Property TableName()
Set(ByVal Value)
Select Case m_CommandType
Case CommandType.Insert
m_SQL &= Value & " () VALUES ()"
Case CommandType.Update
m_SQL &= Value & " SET "
End Select
End Set
End Property
Next: Adding a column to the INSERT or UPDATE command >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee