data binding - ASP.NET dataset add relation null reference exception -


i'm using article guide doing nested data bind of 2 tables 'comment' 'commentotherauthor': http://support.microsoft.com/kb/306154. there may many authors 1 comment. code have here:

.aspx:

<asp:repeater id="rptcomments" runat="server">     <itemtemplate>             <div class="comment-data">                 <h3 class="item">submitted <%# getpagedetails(eval("nodeid")) %> article on <%# eval("created") %></strong></h3>                 <p class="item"><strong>name</strong> <%# eval("firstname") %> <%# eval("surname") %></p>                 <p class="item"><strong>occupation</strong> <%# eval("occupation") %></p>                 <p class="item"><strong>affiliation</strong> <%# eval("affiliation") %></p>                 <p class="item"><strong>email</strong> <a href='mailto:<%# eval("email") %>'><%# eval("email") %></a> <em>publish email: <%# eval("publishemail") %></em></p>                 <p class="item"><strong>competing interests?</strong> <%# eval("competingintereststext") %>&nbsp;</p>                 <p class="item"><strong>eletter title</strong> <%# eval("title") %></p>                 <p><%# eval("comment").tostring().replace("\n", "<br/>")%></p>                  <div class="additional-authors">                     <h3>additional authors</h3>                     <asp:repeater id="rptadditionalauthors" runat="server" datasource='<%# ((datarowview)container.dataitem).row.getchildrows("myrelation") %>' >                         <itemtemplate>                             <%# databinder.eval(container.dataitem, "[\"firstname\"]")%><br>                             </itemtemplate>                     </asp:repeater>                 </div>             </div>     </itemtemplate> </asp:repeater> 

codebehind:

    private void binddata()     {          sqlconnection cnn = new sqlconnection(globalsettings.dbdsn);         sqldataadapter cmd1 = new sqldataadapter(string.format("select * comment {0} order created desc", filter), cnn);          //create , fill dataset.         dataset ds = new dataset();         cmd1.fill(ds, "comments");          //create second dataadapter additional authors table.         sqldataadapter cmd2 = new sqldataadapter("select * commentotherauthor", cnn);         cmd2.fill(ds, "additionalauthors");          //create relation between comments , additional authors tables.         ds.relations.add(             "myrelation",             ds.tables["comment"].columns["id"],             ds.tables["commentotherauthor"].columns["commentid"]         );          //bind authors table parent repeater control, , call databind.         rptcomments.datasource = ds.tables["additionalauthors"];         rptcomments.databind();     } 

however, when running throws system.nullreferenceexception on line ds.relations.add(

i'm not sure start in fixing i'm way out of depth here.

can advise how working?

thanks.

got it! there no actual foreign key constraint joining tables. in place works.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -