代码:
DataRelation rela = new DataRelation("PubTitle",DS.Tables["pub_info"].Columns["pub_id"],DS.Tables["titles"].Columns["pub_id"]);
 DS.Relations.Add(rela);错误提示:
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

解决方案 »

  1.   

    你的datarelation定义时parentcolumn和childcolumn弄反了
      

  2.   

    我重新写了一下
    DataColumn parentColumn;
    parentColumn = DS.Tables["pub_info"].Columns["pub_id"];
    这步就出错了
      

  3.   

    1. 用try catch看一下exception的message是什么?2. 在这一步,用watch看一下,ds、DS.Tables["pub_info"]、DS.Tables["pub_info"].Columns["pub_id"],值是什么?怀疑你的数据填充有问题,ds==null。