日期:2014-05-18  浏览次数:21024 次

反射
请问如何通过反射调用DATASET?

谢谢


------解决方案--------------------
首先定义两个实体类:OFFICEData,UserData
--------------------------------------
OFFICEData:
[System.ComponentModel.DesignerCategory( "Code ")]
[SerializableAttribute]
public class OFFICEData: DataSet,ISerializable
{


public const string T_OFFICE_OFFICEID= "OFFICEID ";
public const string T_OFFICE_CODENO= "CODENO ";
public const string T_OFFICE_SPELLNO= "SPELLNO ";
public const string T_OFFICE_CUSTOMNO= "CUSTOMNO ";
public const string T_OFFICE_STROKENO= "STROKENO ";
public const string T_OFFICE_OFFICE= "OFFICE ";
public const string T_OFFICE_DISEASEAREA= "DISEASEAREA ";
public const string T_OFFICE_BEDAMOUNT= "BEDAMOUNT ";
public const string T_OFFICE_LIMITFUND= "LIMITFUND ";
public const string T_OFFICE_OFFICETYPE= "OFFICETYPE ";
public const string T_OFFICE_DEPARTMENT= "DEPARTMENT ";
public const string T_OFFICE_POSITION= "POSITION ";



private DataTable table;
private DataColumn col;
private ArrayList list;

private UserData user = new UserData();
public UserData userData
{
get{return this.user ;}
set{this.user = value;}
}

private OFFICEData(SerializationInfo info, StreamingContext context) : base(info, context)
{
userData=(UserData)info.GetValue( "myData ",typeof(Serialize.UserData));
}

public OFFICEData()
{

BuildDataTables();
}

public void GetObjectData(SerializationInfo info,StreamingContext text)
{
Type t = typeof(DataSet);

MethodInfo mi =t.GetMethod( "System.Runtime.Serialization.ISerializable.GetObjectData ",BindingFlags.Instance |BindingFlags.NonPublic );
mi.Invoke(this,new object[]{info,text});

info.AddValue( "myData ",userData);
}

//构建业务实体类的结构。
private void BuildDataTables()
{

table = new DataTable( "T_OFFICE ");

table.Columns.Add( "OFFICEID ",typeof(System.Decimal));
table.Columns.Add( "CODENO ",typeof(System.String));
table.Columns.Add( "SPELLNO ",typeof(System.String));
table.Columns.Add( "CUSTOMNO ",typeof(System.String));
table.Columns.Add( "STROKENO ",typeof(System.String));
table.Columns.Add( "OFFICE ",typeof(System.String));
table.Columns.Add( "DISEASEAREA ",typeof(System.String));
table.Columns.Add( "BEDAMOUNT ",typeof(System.Decimal));
table.Columns.Add( "LIMITFUND ",typeof(System.Decimal));
table.Columns.Add( "OFFICETYPE ",ty