结合MyGeneration 的DAAB模板与2006年1月版的Data Access Application Block开发的朋友请注意了.
以前的 DBCommandWrapper 类被去掉了,因为在 .net 2.0 中 System.Data.Common.DbCommand 提供了类似的功能。
以前Database 实例类创建和返回一个 DBCommandWrapper 对象,在2006年1月版 中变成了创建和返回一个DbCommand 对象。
以前Database 实例类的执行,接受一个 DBCommandWrapper 对象,现在是 DbCommand 对象
SetParameterValue, GetParameterValue, AddParameter, AddInParameter, AddOutParameter. 这些原来在 DBCommandWrapper 中的方法,现在移到了 Database 类了,原因当然很简单,System.Data.Common.DbCommand 类 毕竟不是自己可以控制的呀。
以前我们这么写:
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper dbCommand = db.GetStoredProcCommandWrapper("GetProductsByCategory");
dbCommand.AddInParameter("@CategoryID", DbType.Int32, Category);
DataSet productDataSet = db.ExecuteDataSet(dbCommand);
现在我们这么写
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetStoredProcCommand("GetProductsByCategory");
db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, Category);
DataSet productDataSet = db.ExecuteDataSet(dbCommand);
因此原来的DAAB模版不在合适,现我修改模板如下,与朋友共享:
<%
'------------------------------------------------------------------------------
' Copyright 2005 by Noonan Consulting Inc.
' All Rights Reserved
'
' Permission to use, copy, modify, and distribute this software and its
' documentation for any purpose and without fee is hereby granted,
' provided that the above copyright notice appear in all copies and that
' both that copyright notice and this permission notice appear in
' supporting documentation.
'
' NCI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
' SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
' AND FITNESS, IN NO EVENT SHALL NCI BE LIABLE FOR ANY
' SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
' WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
' TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
' OR PERFORMANCE OF THIS SOFTWARE.
'------------------------------------------------------------------------------
' CSharp_DAAB_BusinessEntity.vbgen
' Last Update : 01/31/2005
'------------------------------------------------------------------------------
Dim bFirst
Dim name
Dim alias
Dim objTable
Dim objColumn
Dim tableNames
Dim language
Dim databaseName
Dim database
Dim namespace
Dim props
Dim bOtherColumns
Dim IDbCommand
Dim IDataParameter
Dim ParameterPrefix
Dim dialect
dialect = 1
If input.Item("ckDialect3") Then
dialect = 3
End If
prefix = input.Item("prefix")
' Grab the namespace
namespace = input.Item("txtNamespace")
' Set the Language for our column data types
' Grab the choices the user made in our UI Script (see Interface Code tab)
Set tableNames = input.Item("lstTables")
databaseName = input.Item("cmbDatabase")
Set database = MyMeta.Databases(databaseName)
' Loop through the tables the user selected and generate the business entities
For intLp = 0 To tableNames.Count - 1
Set objTable = database.Tables(tablenames.item(intLp))
Set props = objTable.Properties
bOtherColumns = (objTable.Columns.Count > objTable.PrimaryKeys.Count)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Now we have the table that we desire to build a Business Object From, let us begin.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>/*
'===============================================================================
' Generated From - CSharp_DAAB_BusinessEntity.vbgen
'
' ** IMPORTANT **
' How to Generate your stored procedures:
'
' SQL = SQL_DAAB_StoredProcs.vbgen
'
' This object is 'abstract' which means you need to inherit from it to be able
' to instantiate it. This is very easily done. You can override properties and
' methods in your derived class, this allows you to regenerate this class at any
' time and not worry about overwriting custom code.
'
' NEVER EDIT THIS FILE.
'
' public class YourObject : _YourObject
' {
'
' }
'
'===============================================================================
*/
// Generated by MyGeneration Version # (<%= input.Item("__version") %>)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.IO;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
namespace <%= TrimSpaces(namespace) %>
{
public abstract class <%= "_" & TrimSpaces(objTable.Alias) %>
{
<% output.tabLevel = 2
' List all fields as member variables
For Each objColumn In objTable.Columns
name = GetName(objColumn)
alias = GetAlias(objColumn)
output.autoTabLn "private " & objColumn.LanguageType & " _" & alias & ";"
Next
%> private bool _isNew;
#region Constructors
public <%= "_" & TrimSpaces(objTable.Alias) %>(<%
output.write ")" & vbCrLf
output.tabLevel = 2
output.autoTabLn "{"
output.tabLevel = 3
For Each objColumn in objTable.PrimaryKeys
alias = GetAlias(objColumn)
output.autoTabLn "_" & alias & " = " & GetNullValueDefault(objColumn) & ";"
Next
For Each objColumn in objTable.Columns
If objColumn.IsNullable Then
alias = GetAlias(objColumn)
output.autoTabLn "_" & alias & " = " & GetNullValueDefault(objColumn) & ";"
End If
Next
output.tabLevel = 2
output.autoTabLn "}"
%>
public <%= "_" & TrimSpaces(objTable.Alias) %>(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write objColumn.LanguageType & " " & GetAlias(objColumn)
bFirst = false
Next
output.write ") : this()" & vbCrLf
output.tabLevel = 2
output.autoTabLn "{"
output.tabLevel = 3
For Each objColumn in objTable.PrimaryKeys
alias = GetAlias(objColumn)
output.autoTabLn "_" & alias & " = " & alias & ";"
Next
output.tabLevel = 2
output.autoTabLn "}"
If bOtherColumns Then %>
public <%= "_" & TrimSpaces(objTable.Alias) %>(<%
' List all fields as parameters
bFirst = true
For Each objColumn in objTable.Columns
If Not objColumn.IsComputed Then
If Not bFirst Then
output.write ", "
End If
alias = GetAlias(objColumn)
output.write objColumn.LanguageType & " " & alias
bFirst = False
End If
Next
output.write ") : this()" & vbCrLf
output.tabLevel = 2
output.autoTabLn "{"
output.tabLevel = 3
For Each objColumn in objTable.Columns
If Not objColumn.IsComputed Then
alias = GetAlias(objColumn)
output.autoTabLn "_" & alias & " = " & alias & ";"
End If
Next
output.tabLevel = 2
output.autoTabLn "}"
End If
%>
#endregion
#region Properties
<% For Each objColumn in objTable.Columns
name = GetName(objColumn)
alias = GetAlias(objColumn)
%>
public <%= objColumn.LanguageType %> <%= alias %>
{
get { return _<%= alias %>; }
<% output.tabLevel = 3
If Not objColumn.IsComputed Then
output.autoTabLn "set { _" & alias & " = value; }"
End If
%> }
<% Next %>
public bool IsNew
{
get
{
<% output.tabLevel = 4
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If objColumn.IsAutoKey Then
If Not bFirst Then
output.write " && "
Else
output.autoTab "_isNew = ("
End If
output.write "_" & GetAlias(objColumn) & " == " & GetEmptyValue(objColumn)
bFirst = false
End If
Next
If Not bFirst Then output.writeLn ");"
%> return _isNew;
}
set { _isNew = value; }
}
#endregion
/// <summary>
/// Populates a dataset with info from the database, based on the requested primary key.
/// </summary>
<% output.tabLevel = 2
For Each objColumn in objTable.PrimaryKeys
output.autoTabLn "/// <param name=""" & GetAlias(objColumn) & """>" & objColumn.Description & "</param>"
Next
%> /// <returns>A DataSet containing the results of the query</returns>
private DataSet LoadByPrimaryKey(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write objColumn.LanguageType & " " & GetAlias(objColumn)
bFirst = false
Next
output.write ")" & vbCrLf
%> {
// Create the Database object, using the default database service. The
// default database service is determined through configuration.
SqlDatabase db =(SqlDatabase)DatabaseFactory.CreateDatabase();
string sqlprocName = "<%= CreateProcedureName(objTable, "K") %>";
DbCommand sqlcommand = db.GetStoredProcCommand(sqlprocName);
// Add in parameters
<% If objTable.PrimaryKeys.Count > 0 Then
output.tabLevel = 3
For Each objColumn in objTable.PrimaryKeys
name = GetName(objColumn)
alias = GetAlias(objColumn)
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");"
Next
End If
%>
// DataSet that will hold the returned results
// Note: connection closed by ExecuteDataSet method call
return db.ExecuteDataSet(sqlcommand);
}
/// <summary>
/// Populates current instance of the object with info from the database, based on the requested primary key.
/// </summary>
<% output.tabLevel = 2
For Each objColumn in objTable.PrimaryKeys
output.autoTabLn "/// <param name=""" & GetAlias(objColumn) & """>" & objColumn.Description & "</param>"
Next
%> public virtual void Load(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write objColumn.LanguageType & " " & GetAlias(objColumn)
bFirst = false
Next
output.write ")" & vbCrLf
%> {
// DataSet that will hold the returned results
DataSet ds = this.LoadByPrimaryKey(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write GetAlias(objColumn)
bFirst = false
Next
%>);
// Load member variables from datarow
DataRow row = ds.Tables[0].Rows[0];
<% output.tabLevel = 3
For Each objColumn in objTable.Columns
alias = GetAlias(objColumn)
If objColumn.LanguageType = "Guid" Then
If objColumn.IsNullable Then
output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? " & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];"
Else
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];"
End If
ElseIf objColumn.LanguageType = "byte[]" Then
If objColumn.IsNullable Then
output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? new byte[] {} : row[""" & alias & """] as byte[];"
Else
output.autoTabLn "_" & alias & " = row[""" & alias & """] as byte[];"
End If
ElseIf objColumn.LanguageType = "short" Then
If objColumn.IsNullable Then
output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? (short)" & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];"
Else
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];"
End If
Else
If objColumn.IsNullable Then
output.autoTabLn "_" & alias & " = row.IsNull(""" & alias & """) ? " & GetNullValueDefault(objColumn) & " : (" & objColumn.LanguageType & ")row[""" & alias & """];"
Else
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")row[""" & alias & """];"
End If
End If
Next
%> }
/// <summary>
/// Adds or updates information in the database depending on the primary key stored in the object instance.
/// </summary>
/// <returns>Returns True if saved successfully, False otherwise.</returns>
public bool Save()
{
if (this.IsNew)
return Insert();
else
return Update();
}
/// <summary>
/// Inserts the current instance data into the database.
/// </summary>
/// <returns>Returns True if saved successfully, False otherwise.</returns>
private bool Insert()
{
// Create the Database object, using the default database service. The
// default database service is determined through configuration.
SqlDatabase db =(SqlDatabase)DatabaseFactory.CreateDatabase();
string sqlprocName = "<%= CreateProcedureName(objTable, "I") %>";
DbCommand sqlcommand = db.GetStoredProcCommand(sqlprocName);
// Add parameters
<% If objTable.PrimaryKeys.Count > 0 Then
output.tabLevel = 3
For Each objColumn in objTable.Columns
name = GetName(objColumn)
alias = GetAlias(objColumn)
If objColumn.IsComputed Or (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Then
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");"
Else
If objColumn.IsNullable Then
If objColumn.LanguageType = "byte[]" Then
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & ".Length == 0), _" & alias & "));"
Else
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & " == " & GetNullValueDefault(objColumn) & "), _" & alias & "));"
End If
Else
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", _" & alias & ");"
End If
End If
Next
End If
%>
db.ExecuteNonQuery(sqlcommand);
<% output.tabLevel = 3
bFirst = True
For Each objColumn in objTable.Columns
If (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Or objColumn.IsComputed Then
If bFirst Then
output.autoTabLn ""
output.autoTabLn "// Save output parameter values"
output.autoTabLn "object param;"
bFirst = False
End If
name = GetName(objColumn)
alias = GetAlias(objColumn)
output.autoTabLn "param = db.GetParameterValue(sqlcommand,""" & GetParameterPrefix & name & """);"
output.autoTabLn "if (param == DBNull.Value) return false;"
If objColumn.LanguageType = "Guid" Then
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;"
ElseIf objColumn.LanguageType = "byte[]" Then
output.autoTabLn "_" & alias & " = param as " & objColumn.LanguageType & ";"
Else
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;"
End If
End If
Next
output.autoTabLn ""
output.autoTabLn "return true;"
%> }
/// <summary>
/// Updates the current instance data in the database.
/// </summary>
/// <returns>Returns True if saved successfully, False otherwise.</returns>
public bool Update()
{
// Create the Database object, using the default database service. The
// default database service is determined through configuration.
SqlDatabase db =(SqlDatabase)DatabaseFactory.CreateDatabase();
string sqlprocName = "<%= CreateProcedureName(objTable, "U") %>";
DbCommand sqlcommand = db.GetStoredProcCommand(sqlprocName);
// Add parameters
<% output.tabLevel = 3
For Each objColumn in objTable.Columns
name = GetName(objColumn)
alias = GetAlias(objColumn)
If objColumn.IsComputed Then
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetParameterSize(objColumn) & ");"
Else
If objColumn.IsNullable Then
If objColumn.LanguageType = "byte[]" Then
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & ".Length == 0), _" & alias & "));"
Else
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", SetNullValue((_" & alias & " == " & GetNullValueDefault(objColumn) & "), _" & alias & "));"
End If
Else
output.autoTabLn "db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", _" & alias & ");"
End If
End If
Next
%>
try
{
db.ExecuteNonQuery(sqlcommand);
<% output.tabLevel = 4
bFirst = True
For Each objColumn in objTable.Columns
If (objColumn.IsInPrimaryKey And objColumn.IsAutoKey) Or objColumn.IsComputed Then
If bFirst Then
output.autoTabLn ""
output.autoTabLn "// Save output parameter values"
output.autoTabLn "object param;"
bFirst = False
End If
name = GetName(objColumn)
alias = GetAlias(objColumn)
output.autoTabLn "param = db.GetParameterValue(sqlcommand,""" & GetParameterPrefix & name & """);"
output.autoTabLn "if (param == DBNull.Value) return false;"
If objColumn.LanguageType = "Guid" Then
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;"
ElseIf objColumn.LanguageType = "byte[]" Then
output.autoTabLn "_" & alias & " = param as " & objColumn.LanguageType & ";"
Else
output.autoTabLn "_" & alias & " = (" & objColumn.LanguageType & ")param;"
End If
End If
Next
output.autoTabLn ""
output.autoTabLn "return true;"
%> }
catch
{
return false;
}
}
/// <summary>
/// Removes info from the database, based on the requested primary key.
/// </summary>
<% output.tabLevel = 2
For Each objColumn in objTable.PrimaryKeys
output.autoTabLn "/// <param name=""" & GetAlias(objColumn) & """>" & objColumn.Description & "</param>"
Next
%> public static void Remove(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write objColumn.LanguageType & " " & GetAlias(objColumn)
bFirst = false
Next
output.write ")" & vbCrLf
%> {
// Create the Database object, using the default database service. The
// default database service is determined through configuration.
SqlDatabase db =(SqlDatabase)DatabaseFactory.CreateDatabase();
string sqlprocName = "<%= CreateProcedureName(objTable, "D") %>";
DbCommand sqlcommand = db.GetStoredProcCommand(sqlprocName);
// Add primary keys to command wrapper.
<% If objTable.PrimaryKeys.Count > 0 Then
output.tabLevel = 3
For Each objColumn in objTable.PrimaryKeys
name = GetName(objColumn)
alias = GetAlias(objColumn)
output.autoTabLn " db.AddInParameter(sqlcommand,""" & GetParameterPrefix & name & """, " & objColumn.DbTargetType & ", " & GetAlias(objColumn) & ");"
Next
End If
%>
db.ExecuteNonQuery(sqlcommand);
}
/// <summary>
/// Serializes the current instance data to an Xml string.
/// </summary>
/// <returns>A string containing the Xml representation of the object.</returns>
virtual public string ToXml()
{
// DataSet that will hold the returned results
DataSet ds = this.LoadByPrimaryKey(<%
bFirst = true
For Each objColumn in objTable.PrimaryKeys
If Not bFirst Then
output.write ", "
End If
output.write "_" & GetAlias(objColumn)
bFirst = false
Next
%>);
StringWriter writer = new StringWriter();
ds.WriteXml(writer);
return writer.ToString();
}
/// <summary>
/// Utility function that returns a DBNull.Value if requested. The comparison is done inline
/// in the Insert() and Update() functions.
/// </summary>
private object SetNullValue(bool isNullValue, object value)
{
if (isNullValue)
return DBNull.Value;
else
return value;
}
}
}
<%
' Save the output file for this Table
Dim filename
filename = input.item("txtPath")
Dim length
Dim pos
lenth = Len(filename)
pos = InStrRev(filename, "\")
If Not pos = lenth Then
filename = filename & "\"
End If
If prefix = True Then
filename = filename & "_" & TrimSpaces(objTable.Alias) & ".cs"
Else
filename = filename & TrimSpaces(objTable.Alias) & ".cs"
End If
output.save filename, false
buffer = buffer & output.text
output.clear
Next ' tableName
output.write buffer
%>
<%
'===========================================================================
' These are support routines called by the above scirpt
'===========================================================================
Function GetAlias(objColumn)
Dim alias
alias = TrimSpaces(objColumn.Alias)
GetAlias = UCase(Left(alias, 1)) & Right(alias, Len(alias) -1)
End Function
Function GetName(objColumn)
Dim name
name = objColumn.Name
GetName = UCase(Left(name, 1)) & Right(name, Len(name) -1)
End Function
Function TrimSpaces(str)
Dim tname
Dim name
Dim char
Dim l
name = ""
tname = str
l = Len(tname)
For j = 1 To l
char = Mid(tname, j, 1)
If Not char = " " Then
name = name & char
End If
Next
TrimSpaces = name
End Function
Function GetParameterPrefix
Select Case MyMeta.DbTarget
Case "OleDb"
GetParameterPrefix = "@"
Case "SqlClient"
GetParameterPrefix = "@"
Case "OracleClient"
GetParameterPrefix = "p_"
Case "FirebirdSql"
GetParameterPrefix = "@"
End Select
End Function
Function CreateProcedureName(objTable, suffix)
Dim bFirst
Dim str
bFirst = true
Select Case suffix
Case "L"
str = "Get"
Case "K"
str = "Get"
Case "U"
str ="Update"
Case "I"
str = "Add"
Case "D"
str = "Delete"
End Select
CreateProcedureName = "daab_" & str & TrimSpaces(objTable.Name)
End Function
Function GetFullType(objColumn)
Select Case LCase(objColumn.LanguageType)
Case "string"
GetFullType = "String"
Case "int"
GetFullType = "Int32"
Case "short"
GetFullType = "Short"
Case "decimal"
GetFullType = "Decimal"
Case "datetime"
GetFullType = "DateTime"
Case "byte[]"
GetFullType = "Byte"
Case "bool"
GetFullType = "Boolean"
Case Else
GetFullType = objColumn.LanguageType
End Select
End Function
Function GetEmptyValue(objColumn)
Select Case objColumn.DbTargetType
Case "SqlDbType.Int16", "DbType.Int32", "DbType.Int64", "DbType.Decimal", "DbType.Double", "DbType.Currency", "DbType.Single","SqlDbType.BigInt","SqlDbType.Decimal ","SqlDbType.Float","SqlDbType.Int","SqlDbType.Money","SqlDbType.Real","SqlDbType.SmallInt ","SqlDbType.SmallMoney ","SqlDbType.TinyInt"
GetEmptyValue = "0"
Case "DbType.Guid","SqlDbType.UniqueIdentifier"
GetEmptyValue = "Guid.Empty"
Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength", "DbType.String", "DbType.AnsiString","SqlDbType.NChar ","SqlDbType.NText ","SqlDbType.NVarChar","SqlDbType.Text ","SqlDbType.VarChar","SqlDbType.Char"
GetEmptyValue = "string.Empty"
Case Else
GetEmptyValue = Replace(objColumn.DbTargetType, "DbType.", "")
End Select
End Function
Function GetParameterSize(objColumn)
Select Case objColumn.DbTargetType
Case "DbType.Int32"
GetParameterSize = "4"
Case "DbType.Binary"
GetParameterSize = "8"
Case "DbType.Guid"
GetParameterSize = "16"
Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength", "DbType.String", "DbType.AnsiString","SqlDbType.NChar ","SqlDbType.NText ","SqlDbType.NVarChar","SqlDbType.Text ","SqlDbType.VarChar","SqlDbType.Char"
GetParameterSize = objColumn.CharacterMaxLength
Case Else
GetParameterSize = "0"
End Select
End Function
Function GetNullValueDefault(objColumn)
Select Case objColumn.DbTargetType
Case "DbType.Int16", "DbType.Int32", "DbType.Int64", "DbType.Decimal", "DbType.Double", "DbType.Currency", "DbType.Single","SqlDbType.BigInt","SqlDbType.Decimal ","SqlDbType.Float","SqlDbType.Int","SqlDbType.Money","SqlDbType.Real","SqlDbType.SmallInt ","SqlDbType.SmallMoney ","SqlDbType.TinyInt"
GetNullValueDefault = "0"
Case "DbType.Guid"
GetNullValueDefault = "Guid.Empty"
Case "DbType.StringFixedLength", "DbType.AnsiStringFixedLength","DbType.VarChar", "DbType.NVarChar", "DbType.AnsiString","SqlDbType.NChar ","SqlDbType.NText ","SqlDbType.NVarChar","SqlDbType.Text ","SqlDbType.VarChar","SqlDbType.Char"
GetNullValueDefault = "string.Empty"
Case "DbType.DateTime","SqlDbType.DateTime" ,"SqlDbType.SmallDateTime"
GetNullValueDefault = "DateTime.Parse(""01/01/1900"")"
Case "DbType.Boolean","SqlDbType.Bit"
GetNullValueDefault = "false"
Case "DbType.Binary", "DbType.Byte" ,"SqlDbType.Binary ","SqlDbType.VarBinary "
GetNullValueDefault = "new byte[] {}"
Case "DbType.Object","SqlDbType.Variant"
GetNullValueDefault = "null"
Case Else
GetNullValueDefault = objColumn.DbTargetType '"string.Empty"
End Select
End Function
%>