zoukankan      html  css  js  c++  java
  • 根据数据库字段类型返回c#类型函数

    <%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" ResponseEncoding="UTF-8"   Src="" Inherits="" Debug="False" Description="Template description here." %>
    <%@ Property Name="ProcedureName" Type="String" Default="" Optional="False" Category="" Description=""%>
    <%@ Assembly Name="SchemaExplorer" %>
    <%@ Import Namespace="SchemaExplorer" %>
    <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Default="" Optional="False" Category="" Description=""%>
    <script runat="template">
    public string GetCSharpVariableType(ColumnSchema column)
    {
     if (column.Name.EndsWith("TypeCode")) return column.Name;
     
     switch (column.DataType)
     {
      case DbType.AnsiString: return "string";
      case DbType.AnsiStringFixedLength: return "string";
      case DbType.Binary: return "byte[]";
      case DbType.Boolean: return "bool";
      case DbType.Byte: return "byte";
      case DbType.Currency: return "decimal";
      case DbType.Date: return "DateTime";
      case DbType.DateTime: return "DateTime";
      case DbType.Decimal: return "decimal";
      case DbType.Double: return "double";
      case DbType.Guid: return "Guid";
      case DbType.Int16: return "short";
      case DbType.Int32: return "int";
      case DbType.Int64: return "long";
      case DbType.Object: return "object";
      case DbType.SByte: return "sbyte";
      case DbType.Single: return "float";
      case DbType.String: return "string";
      case DbType.StringFixedLength: return "string";
      case DbType.Time: return "TimeSpan";
      case DbType.UInt16: return "ushort";
      case DbType.UInt32: return "uint";
      case DbType.UInt64: return "ulong";
      case DbType.VarNumeric: return "decimal";
      default:
      {
       return "__UNKNOWN__" + column.NativeType;
      }
     }
    }
    </script>
      public static long Insert_<%=SourceTable.Name%>(<%for(int i=0;i<SourceTable.Columns.Count;i++){%><%=GetCSharpVariableType(SourceTable.Columns[i])%> <%=SourceTable.Columns[i].Name%><%if(i<SourceTable.Columns.Count-1){%>,<%}%><%}%>)
      {
       long InfoStatus=-101;                                                      
       InfoStatus = Convert.ToInt32(SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings["connString"], "<%=ProcedureName%>",<%for(int i=0;i<SourceTable.Columns.Count;i++){%><%=SourceTable.Columns[i].Name%><%if(i<SourceTable.Columns.Count-1){%>,<%}%><%}%>));
       return InfoStatus;
      }
     
  • 相关阅读:
    睡前一分钟打造完美下半身 健康程序员,至尚生活!
    几种不伤身体的速效减肥秘方 健康程序员,至尚生活!
    头发一周洗几次才适宜? 健康程序员,至尚生活!
    夏日驱蚊虫蟑螂的最好办法! 健康程序员,至尚生活!
    WPF控件和布局
    《深入浅出WPF》笔记——绑定篇(二)
    WPF中的DataTemplate绑定使用的场合
    WPF第一个程序和XAML初探
    实习总结之jquery实例
    下一步要实战的东西
  • 原文地址:https://www.cnblogs.com/hhq80/p/994098.html
Copyright © 2011-2022 走看看