Wednesday, September 08, 2010
  Search
 
Register
Login
 
How to Install and Configure ActiveDirectory Provider for DotNetNuke 5.0
 The directions for installing and configuring extensions in DotNetNuke 5.0 are very similiar, but slightly different than from previous versions. Here's how to install the ActiveDirectory authentica...

Find this article and more in the category

Read This Article . . .

Quick Look at Some New Features of DotNetNuke 5 Cambrian
DotNetNuke’s much anticipated Cambrian has finally been made available as a Release Candidate and while it looks like the same ol’ packages from afar, it’s packed with some nice new features that are...

Find this article and more in the category

Read This Article . . .

I Need to Modify the What to Install DNN? What in the World is a Web.Config File Anyway??
 If you're wondering what in the world a web.config file is, then wonder know more. . .in about 5 minutes, you'll know more than you do now and be well on your way to moving forward.

Find this article and more in the Web.Config category

Read This Article . . .

New "Styles" SkinObject Found in DotNetNuke 4.9
One more addition has been added to the developer's DotNetNuke skinning toolbox with the release of DotNetNuke 4.9. Introducing...the Styles SkinObject. This little object is a very welcome addition ...

Find this article and more in the DotNetNuke category

Read This Article . . .

Everything You Never Wanted to Know About the Config File
This is the "pre-" first installment in a series that will cover the parts of the web.config file to give you an idea of how to manipulate and customize your DotNetNuke portal. The web.config fi...

Find this article and more in the category

Read This Article . . .

Quick Check for Troubleshooting the CodeEndeavor Ajax Templates
I haven’t just installed the the template and created a module out of the box yet. However, I have come across a few things that I know to check and fix and I’m up and running in no time at all. If y...

Find this article and more in the category

Read This Article . . .

Quick Check for Troubleshooting the CodeEndeavor Ajax Templates
I haven’t just installed the the template and created a module out of the box yet. However, I have come across a few things that I know to check and fix and I’m up and running in no time at all. If y...

Find this article and more in the category

Read This Article . . .

More Ways to Install DotNetNuke Modules with the URL Method
While DotNetNuke has a built in mechanism for installing modules, there is another method you can use as well. This is a great alternative to use especially when you are trying to install larger mod...

Find this article and more in the category

Read This Article . . .

Simple Intro to the DNN UserInfo Class
 New DNN developers often wonder how to expose information about logged in users to a custom DotNetNuke module. So, I threw together a very simple example to show how easy it is to begin using the bu...

Find this article and more in the DotNetNuke category

Read This Article . . .

Setting Up the DotNetNuke Side of Multi-Websites
Ok, so by now you know that DotNetNuke can handle multiple websites, but you still want to know why. Well, it’s pretty easy once you know how to do it, but it can be pretty confusing to some who are ...

Find this article and more in the category

Read This Article . . .

Search for Articles

Virtual-Essential's DotNetNuke, .NET, and SQL Tips For the Developer

Minimize
Mar 13

Written by: Briana Tarrance
3/13/2010 10:57 AM 

First, I created a function to map SQL data types to VB.NET data types. Again, this isn’t a full collection, just enough for my testing.

 

-- =============================================
-- Author:        Briana Tarrance
-- Create date: 03/10/2010
-- Description:    Fun way to use SQL to generate code for you.
-- copyright(c) 2010. Virtual-Essentials.com and HowToDotNetNuke.com
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[getVBDataType] 
(
        @coltype varchar(25)
)
RETURNS varchar(25)
AS
BEGIN
        DECLARE @Result varchar(25)
        SELECT @Result = 
            CASE Lower(@coltype)
                WHEN 'int' THEN 'Integer' 
                WHEN '%char%' THEN 'String' 
                WHEN '%text%' THEN 'String' 
                WHEN 'money' THEN 'Decimal'
                WHEN 'datetime' THEN 'DateTime'
                WHEN 'bit' THEN 'Boolean'
                ELSE 'String'
            END
            
        RETURN @Result
END

Then, I created a script that would loop through the tables in my database and create a class for each of them.

DECLARE @Database as varchar(100)
DECLARE tables CURSOR LOCAL FAST_FORWARD FOR 

SELECT  TABLE_NAME, TABLE_CATALOG
FROM INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_NAME;

DECLARE @@tablename as varchar(100)
OPEN tables
        FETCH FROM tables INTO @@tablename,  @Database
WHILE @@Fetch_Status  = 0
BEGIN
        PRINT 'Namespace ' + @Database
        PRINT 'Public Class ' + @@tablename


DECLARE @@column varchar(100)
DECLARE @@coltype varchar(100)
DECLARE @@position int
DECLARE @@catalog varchar(100)
DECLARE @@table varchar(100)


PRINT ''
PRINT '#Region "Structs" '
PRINT '  Public Sub New()'
PRINT '  End Sub'
PRINT '  '
PRINT '  Public Sub New()'

DECLARE structs CURSOR LOCAL FAST_FORWARD FOR 
SELECT  
COLUMN_NAME, DATA_TYPE
FROM  
   INFORMATION_SCHEMA.COLUMNS 
WHERE  
   TABLE_NAME = @@tablename
OPEN structs
        FETCH FROM structs INTO @@column, @@coltype
WHILE @@Fetch_Status  = 0
BEGIN 
        PRINT '     Me.' + @@column + '= _' + lower(@@column)

FETCH FROM structs INTO @@column, @@coltype
END

CLOSE structs
DEALLOCATE structs
PRINT '  End Sub'
PRINT '#End Region'
PRINT ''


PRINT '#Region "Public Properties" '
DECLARE members CURSOR LOCAL FAST_FORWARD FOR 
SELECT COLUMN_NAME, DATA_TYPE
FROM  
   INFORMATION_SCHEMA.COLUMNS 
WHERE  
   TABLE_NAME = @@tablename
OPEN members
        FETCH FROM members INTO @@column, @@coltype
WHILE @@Fetch_Status  = 0
BEGIN 
        PRINT 'Private _' + lower(@@column) + ' as ' + dbo.getVBDataType(@@coltype)
        PRINT 'Public Property ' + @@column + '() as ' + dbo.getVBDataType(@@coltype)
        PRINT '   Get'
        PRINT '      ' + @@column + ' = _' + Lower(@@column)
        PRINT '   End Get'
        PRINT '   Set(ByVal value as ' + dbo.getVBDataType(@@coltype) + ')'
        PRINT '      _' + Lower(@@column) + ' = value '
        PRINT '   End Set'
        PRINT 'End Property'
        PRINT ' ' 

FETCH FROM members INTO @@column, @@coltype
END
Print '#End Region'
CLOSE members
DEALLOCATE members



        PRINT 'End Class'
        PRINT 'End Namespace'
PRINT '''-------------------------------------------------------------------------'
FETCH FROM tables INTO @@tablename,  @Database
END

CLOSE tables
DEALLOCATE tables

Obviously, more can be done with this code to make it work better, but I thought it was a fun start. I’d love to hear the feedback. Holla! :-)

**DISCLAIMER** This code is not intended to be used in a production environment and is not guaranteed in any way. Use at your own risk.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
 
 
Copyright 2008 by Virtual-Essentials.com Privacy Statement    Terms Of Use