本文介绍了无法将类型'System.Data.DataRelation'隐式转换为'DataRelation'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码出现错误.

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"]);
        }
    }
}



请帮帮我..

[edit]已添加代码块-OriginalGriff [/edit]



pls help me..

[edit]Code block added - OriginalGriff[/edit]

推荐答案

System.Data.DataRelation relation;

就我个人而言,如果我要使用System.Data,我不会将我的类称为冲突名称,只是为了避免混淆!

Personally, if I was going to use System.Data, I would not call my class a conflicting name, just to avoid confusion!


这篇关于无法将类型'System.Data.DataRelation'隐式转换为'DataRelation'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 07:08