简体   繁体   中英

C# datarow getchildrow returns no rows

In my DB there are three tables R(id,num) RT(Rid,Tid) T(id,hour) And there is 1 to many relationship between (R and RT) and (T and RT). I am using a Dataset to access my DB.

Now I am using code below to retrieve data and it returns empty list:

foreach (mDataSet.RTRow rtRow in rRow.GetRTRows())
      console.writeln(rtRow.Tid);//never reaches this line

Code for inserting value:

rTableAdapter.insert(r.id,num);
tTableAdapter.insert(t.id,hour);
rtTableAdapter.insert(r.id,t.id);

Does anyone know what is the problem that I get now rows

Obvious question first: does mDataSet contain data in the table RT ? In your comment you state that the DB is not empty, but is the dataset also not empty?

Second, when I encountered this problem, it eventually had to do something with the relation as definied in the designer. When you double click the line between the two tables R and RT (the line with a key symbol on one side and and infinity symbol on the other side), you can examine the properties. Just make sure that the correct columns from both tables participate in the foreign key relation.

As an aside: do you really use such short names for your table and variable names or was it just to provide an example?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM