A Wrapper Class for DML Statements Using Visual Basic.NET (Page 1 of 7 )
This article explains several techniques for working with DML statements in a flexible manner, without worrying much about the syntactical errors.
A downloadable file for this article is available
here.
The entire source code for this article is available in the form of downloadable zip. The solution was developed using Microsoft Visual Studio 2003 Enterprise Architect with Microsoft SQL Server 2005 Developer Edition on Microsoft Windows Server 2003 Enterprise Edition. Even though I believe that the source code available with this contribution can work with Microsoft Visual Studio.NET 2002, I didn't really test it in any other environment. I request that you post in the discussion area if you have any problems with execution.
What exactly is this DML support class doing?
In several applications, we use DML statements which execute dynamically. If we are working with an INSERT statement that has too many columns, it would be rather daunting. The same would be true for an UPDATE statement with many columns.
To solve all these issues, I developed a simple wrapper class specifically to work with DML statements flexibly. As part of what was needed, I declared the following enumerations:
PublicEnum CommandType
Insert
Update
End Enum
PublicEnum DataType
NumericType
CharacterType
DateType
EndEnum
When we work with a DML statement, it would be generally an INSERT, UPDATE or DELETE (putting SELECT aside). DELETE is very simple and I simply don't want to handle it in this class. That is why I declared only "Insert" and "Update" as part of the "Command Type."
When working with DML commands, the syntax will be different based on the data types. To support different data types, I declared the above enumeration.
To execute the DML command, I am using the Data Helper class developed by me in my previous articles. If you want to include your own code, I request that you go ahead by forgetting the data helper code. You can also modify this class with respect to Microsoft Data Access Blocks.
Next: The beginning of the class >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee