Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi all fri,

here i have problem about data relation in ms sql.
i have 2 tables, A and B
A _ JobID (pk)
B _ JobID

i want to make one-to-one relation in dataset designer
Q1. how to set it? ( for me, 1-many is ok)

after i 1-1 relation in designer,
for (int i = 0; i < gridView1.SelectedRowsCount; i++)
            {
                if (gridView1.GetSelectedRows()[i] >= 0)
                    rows.Add(gridView1.GetDataRow(gridView1.GetSelectedRows()[i]));
                    
            }
            for (int j = 0; j < rows.Count; j++)
            {
                DataRow selectedRow = gridView1.GetFocusedDataRow();

                bRow= selectedRow as MyDataSet.BTableRow;
            
                DataRow parents = bRow.GetParentRow(dataRelation);               
                
            }


i have set dataRelation variable like this
string relation = "ATable_BTable";

DataRelation dataRelation = MyDataSet.BTable.ParentRelations[relation];


In designer, i set correct key column, foreign key column, parent table and child table.

But what's wrong in my code, i got null value in parents datarow although there are 1-1 mapping in DataTable(Database) .
I used the similar way in 1-many relation in other two tables that use the "ChildRelation" .
My tools visual studio 2010, ms sql , c#

Anyone wants to help me? I spent nearly one day :( so bad
thanks in advance
Posted
Updated 14-May-12 23:20pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900