Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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);
        con.Open();
        da1.Fill(ds, "Production.Product");
        da2.Fill(ds, "Sales.SalesOrderDetail");
        con.Close();
 
        relation = ds.Relations.Add("CustOrders",
            ds.Tables["Production.Product"].Columns["ProductID"],
            ds.Tables["Sales.SalesOrderDetail"].Columns["ProductID"]);
 
        foreach (DataRow pRow in ds.Tables["Production.Product"].Rows)
        {
            Console.WriteLine(pRow["ProductID"]);
            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
Edited 27-Sep-12 22:39pm
v2

1 solution

Rate this: bad
good
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!
  Permalink  
Comments
vision01 at 28-Sep-12 4:19am
   
thanks OriginalGriff..!
OriginalGriff at 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
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
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