大家在自己创建datatable的时候,在创建列的时候可能会遇到
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.ColumnName = "khlxdh";
column.AutoIncrement = true;
column.Caption = "";
column.ReadOnly = true;
column.Unique = true;
table.Columns.Add(column);
System.Type.GetType 取出的是 null 的情况,这里就需要 写上完整的
Type.AssemblyQualifiedName 属性,其中包括从中加载 Type 的程序集的名称。
具体获取方法如下:
using System;
using System.Reflection;
class MyAssemblyClass
{
public static void Main()
{
Type objType = typeof(System.Array);//填入想要获取的类型
// Print the full assembly name.
Console.WriteLine ("Full assembly name: {0}.", objType.Assembly.FullName.ToString());
// Print the qualified assembly name.
Console.WriteLine ("Qualified assembly name: {0}.", objType.AssemblyQualifiedName.ToString());
}
}
既能得到想要的类型了,然后将生成的字符串填入System.Type.GetType 既能获取到了
本文介绍了一种在创建DataTable列时遇到的问题及解决方案,当使用System.Type.GetType方法时返回null,文章提供了通过Type.AssemblyQualifiedName属性获取正确类型的示例代码。
825

被折叠的 条评论
为什么被折叠?



