• <i id='jtPdf'><tr id='jtPdf'><dt id='jtPdf'><q id='jtPdf'><span id='jtPdf'><b id='jtPdf'><form id='jtPdf'><ins id='jtPdf'></ins><ul id='jtPdf'></ul><sub id='jtPdf'></sub></form><legend id='jtPdf'></legend><bdo id='jtPdf'><pre id='jtPdf'><center id='jtPdf'></center></pre></bdo></b><th id='jtPdf'></th></span></q></dt></tr></i><div id='jtPdf'><tfoot id='jtPdf'></tfoot><dl id='jtPdf'><fieldset id='jtPdf'></fieldset></dl></div>

  • <small id='jtPdf'></small><noframes id='jtPdf'>

        <legend id='jtPdf'><style id='jtPdf'><dir id='jtPdf'><q id='jtPdf'></q></dir></style></legend>
        • <bdo id='jtPdf'></bdo><ul id='jtPdf'></ul>

        <tfoot id='jtPdf'></tfoot>

        SQL Server 到 .Net 类型的转换

        SQL Server to .Net type conversions(SQL Server 到 .Net 类型的转换)
      1. <i id='1LE6J'><tr id='1LE6J'><dt id='1LE6J'><q id='1LE6J'><span id='1LE6J'><b id='1LE6J'><form id='1LE6J'><ins id='1LE6J'></ins><ul id='1LE6J'></ul><sub id='1LE6J'></sub></form><legend id='1LE6J'></legend><bdo id='1LE6J'><pre id='1LE6J'><center id='1LE6J'></center></pre></bdo></b><th id='1LE6J'></th></span></q></dt></tr></i><div id='1LE6J'><tfoot id='1LE6J'></tfoot><dl id='1LE6J'><fieldset id='1LE6J'></fieldset></dl></div>
        <tfoot id='1LE6J'></tfoot>
        • <small id='1LE6J'></small><noframes id='1LE6J'>

          <legend id='1LE6J'><style id='1LE6J'><dir id='1LE6J'><q id='1LE6J'></q></dir></style></legend>

              <bdo id='1LE6J'></bdo><ul id='1LE6J'></ul>
                <tbody id='1LE6J'></tbody>
                • 本文介绍了SQL Server 到 .Net 类型的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下映射,用于在 SQL Server 类型、SQLData 类型和 .NET 类型之间进行转换:

                  I have the following map that I use to convert betwen SQL Server types, SQLData types, and .NET types:

                  /// <summary>
                      /// The map of types. THis maps all the corresponding types between sql server types, .net sql types, and .net types
                      /// </summary>
                      public static List<SqlTypeConversionHolder> TypeList = new List<SqlTypeConversionHolder>()
                      {
                          new SqlTypeConversionHolder("bigint", typeof(SqlInt64),typeof(Int64)),
                          new SqlTypeConversionHolder("binary", typeof(SqlBytes),typeof(Byte[])),
                          new SqlTypeConversionHolder("bit", typeof(SqlBoolean),typeof(Boolean)),
                          new SqlTypeConversionHolder("char", typeof(SqlChars),typeof(char)), //this one may need work
                          new SqlTypeConversionHolder("cursor", null,null),
                          new SqlTypeConversionHolder("date", typeof(SqlDateTime),typeof(DateTime)),
                          new SqlTypeConversionHolder("datetime", typeof(SqlDateTime),typeof(DateTime)),
                          new SqlTypeConversionHolder("datetime2", null,typeof(DateTime)),
                          new SqlTypeConversionHolder("DATETIMEOFFSET", null,typeof(DateTimeOffset)),
                          new SqlTypeConversionHolder("decimal", typeof(SqlDecimal),typeof(Decimal)),
                          new SqlTypeConversionHolder("float", typeof(SqlDouble),typeof(Double)),
                          //new SqlTypeConversionHolder("geography", typeof(SqlGeography),typeof(null));
                          //new SqlTypeConversionHolder("geometry", typeof(SqlGeometry),typeof(null));
                          //new SqlTypeConversionHolder("hierarchyid", typeof(SqlHierarchyId),typeof(null));
                          new SqlTypeConversionHolder("image", null,null),
                          new SqlTypeConversionHolder("int", typeof(SqlInt32),typeof(Int32)),
                          new SqlTypeConversionHolder("money", typeof(SqlMoney),typeof(Decimal)),
                          new SqlTypeConversionHolder("nchar", typeof(SqlChars),typeof(String)),
                          new SqlTypeConversionHolder("ntext", null,null),
                          new SqlTypeConversionHolder("numeric", typeof(SqlDecimal),typeof(Decimal)),
                          new SqlTypeConversionHolder("nvarchar", typeof(SqlChars),typeof(String)),
                          new SqlTypeConversionHolder("nvarchar(1)", typeof(SqlChars),typeof(Char)),
                          new SqlTypeConversionHolder("nchar(1)", typeof(SqlChars),typeof(Char)),
                          new SqlTypeConversionHolder("real", typeof(SqlSingle),typeof(Single)),
                          new SqlTypeConversionHolder("rowversion", null,typeof(Byte[])),
                          new SqlTypeConversionHolder("smallint", typeof(SqlInt16),typeof(Int16)),
                          new SqlTypeConversionHolder("smallmoney", typeof(SqlMoney),typeof(Decimal)),
                          new SqlTypeConversionHolder("sql_variant", null,typeof(Object)),
                          new SqlTypeConversionHolder("table", null,null),
                          new SqlTypeConversionHolder("text", typeof(SqlString),typeof(string)), //this one may need work
                          new SqlTypeConversionHolder("time", null,typeof(TimeSpan)),
                          new SqlTypeConversionHolder("timestamp", null,null),
                          new SqlTypeConversionHolder("tinyint", typeof(SqlByte),typeof(Byte)),
                          new SqlTypeConversionHolder("uniqueidentifier", typeof(SqlGuid),typeof(Guid)),
                          new SqlTypeConversionHolder("varbinary", typeof(SqlBytes),typeof(Byte[])),
                          new SqlTypeConversionHolder("varbinary(1)", typeof(SqlBytes),typeof(byte)),
                          new SqlTypeConversionHolder("binary(1)", typeof(SqlBytes),typeof(byte)),
                          new SqlTypeConversionHolder("varchar", typeof(SqlString),typeof(string)), //this one may need work
                          new SqlTypeConversionHolder("xml", typeof(SqlXml),typeof(string))
                      };
                  

                  SqlTypeConversionHolder 的第一个参数是 sql server 类型的名称.第二个参数是 .Net Sql 类型.第三种是.net类型.

                  The first parameter of a SqlTypeConversionHolder is the name of the sql server type. The second parameter is the .Net Sql type. The third is the .net type.

                  那些说 This one may need work 是我不确定的.有人可以就正确的转换提供一些帮助吗?在 MSDN 上查看,似乎他们没有正确的转换类型.我觉得这很难相信.从 SQL Server 类型到 .NET 类型必须有某种方法.

                  The ones that say This one may need work are the ones that I am not sure about. Could someone provide some help as to what the proper conversions would be? Looking on MSDN, it seems as if they dont have a proper conversion type. I find that hard to beleive. There has to be someone way to go from the SQL Server type to the .NET type.

                  推荐答案

                  char 不是 SQL Server char 的正确 .NET 数据类型.它必须转换为 char[]string,因为 SQL char 可以包含多个字符.

                  char is not the correct .NET data type for a SQL Server char. It must be converted to either char[] or string, since a SQL char can hold more than one character.

                  微软参考这里同意我的看法.其他的看起来是正确的.

                  The Microsoft reference here agrees with me. The other ones look correct.

                  这篇关于SQL Server 到 .Net 类型的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  CreateDelegate with unknown types(具有未知类型的 CreateDelegate)
                  Does Funclt;Tgt;.BeginInvoke use the ThreadPool?(Funclt;Tgt;.BeginInvoke 使用线程池吗?)
                  How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)

                  <tfoot id='2iV2c'></tfoot>
                    • <bdo id='2iV2c'></bdo><ul id='2iV2c'></ul>

                          1. <i id='2iV2c'><tr id='2iV2c'><dt id='2iV2c'><q id='2iV2c'><span id='2iV2c'><b id='2iV2c'><form id='2iV2c'><ins id='2iV2c'></ins><ul id='2iV2c'></ul><sub id='2iV2c'></sub></form><legend id='2iV2c'></legend><bdo id='2iV2c'><pre id='2iV2c'><center id='2iV2c'></center></pre></bdo></b><th id='2iV2c'></th></span></q></dt></tr></i><div id='2iV2c'><tfoot id='2iV2c'></tfoot><dl id='2iV2c'><fieldset id='2iV2c'></fieldset></dl></div>
                            <legend id='2iV2c'><style id='2iV2c'><dir id='2iV2c'><q id='2iV2c'></q></dir></style></legend>
                          2. <small id='2iV2c'></small><noframes id='2iV2c'>

                              <tbody id='2iV2c'></tbody>