Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select of a child table return double number of rows than it should

$
0
0

Hi,

I have this code:

                 string prname = Console.ReadLine();

                SqlDataAdapter spjadap =  new SqlDataAdapter("select * from spj", connString);
                spjadap.Fill(ds, "tab");
                DataColumn parentcol = ds.Tables["j"].Columns["j#"];

                DataColumn childcol = ds.Tables["tab"].Columns["j#"];
                DataRelation dr = new DataRelation("tab_j", parentcol, childcol);

                ds.Relations.Add(dr);

                DataTable spjtable1 = ds.Tables["tab"];
                DataRow[] rows = spjtable1.Select("Parent.jname = '" + prname + "'");
                if (rows.Length == 0)
                {
                    Console.WriteLine(something);
                }
                foreach (DataRow row in rows)

                { Console.WriteLine(@"for " + prname + " are: P# = " + row["p#"]); }

but instead of supposed, expected number of rows, it reurns double number of rows.

Can anybody help me please where is my mistake?

Thanks





Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>