Click here to Skip to main content
12,696,920 members (31,350 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET ADO.NET C#4.0
Im getting error in following code.

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class DataRelation : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        string connetionString = null;
        SqlConnection con;
        SqlDataAdapter da1;
        SqlDataAdapter da2;
        DataRelation relation;
        SqlCommand command = new SqlCommand();
        DataSet ds = new DataSet();
        connetionString = ConfigurationManager.ConnectionStrings["ConnectionStringDemo"].ConnectionString.ToString();
        con = new SqlConnection(connetionString);
        da1 = new SqlDataAdapter("select  top  (20)* from Production.Product", con);
        da2 = new SqlDataAdapter("select  top  (20) * from Sales.SalesOrderDetail", con);
        da1.Fill(ds, "Production.Product");
        da2.Fill(ds, "Sales.SalesOrderDetail");

        relation = ds.Relations.Add("CustOrders",

        foreach (DataRow pRow in ds.Tables["Production.Product"].Rows)
            foreach (DataRow cRow in pRow.GetChildRows(relation))
                Console.WriteLine("\t" + cRow["SalesOrderID"]);

pls help me..

[edit]Code block added - OriginalGriff[/edit]
Posted 27-Sep-12 22:37pm
Updated 27-Sep-12 22:39pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The System.Data namespace already contains a class called DataRelation, and this is returned from a DataSet.Relations.Add method call.
The variable you have tried to store it in is declared as a DataRelation - which is the class name your method sits in. There is no conversion defined between the two unrelated types.

Either change the name of your class (but don't change the definition of relation) or fully qualify the definition:
System.Data.DataRelation relation;
Personally, if I was going to use System.Data, I would not call my class a conflicting name, just to avoid confusion!
vision01 28-Sep-12 4:19am
thanks OriginalGriff..!
OriginalGriff 28-Sep-12 5:04am
You're wecome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100