日期:2014-05-18  浏览次数:21300 次

错误1“DataRelation”是“命名空间”,但此处被当做“类型”来使用
C# code
#region using Directives
using System;
using System.Data;    //Use ADO.NET namespace
using System.Data.SqlClient;  //Use SQL Server data provider namespace
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion
namespace DataRelation
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection thisConnection = new SqlConnection("user id=pos;PWD=PO$$IBLE;Server=192.168.2.44;DataBase=gdbranch;TimeOut=30;");
            SqlDataAdapter thisAdapter = new SqlDataAdapter(
                "SELECT CustomerID,Customername from Customers", thisConnection);
            SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
            DataSet thisDataSet = new DataSet();
            SqlDataAdapter custAdapter=new SqlDataAdapter(
                "Select * from customers",thisConnection);
            SqlDataAdapter orderAdapter=new SqlDataAdapter(
                "SELECT * FROM Orders",thisConnection);
            custAdapter.Fill(thisDataSet,"Customers");
            orderAdapter.Fill(thisDataSet,"Orders");

            DataRelation custOrderRel = thisDataSet.Relations.Add("CustOrders",
                thisDataSet.Tables["Customers"].Columns["CustomerID"],
                thisDataSet.Tables["Orders"].Columns["CustomerID"]);
            foreach(DataRow custRow in thisDataSet.Tables["Customers"].Rows)
            {
                Console.WriteLine("Customer ID:"+custRow["CustomerID"]+
                    "Name:"+custRow["CompanyName"]);
                foreach (DataRow orderRow in custRow.GetChildRows(custOrderRel))
                {
                    Console.WriteLine(" Order ID:"+orderRow["OrderID"]);
                }
            }
            thisConnection.Close();
            Console.Write("Program finished,press Enter/Return to continue:");
            Console.ReadLine();

        }
    }
}


请问下面这句代码有什么问题?该怎么怎么写?
C# code
DataRelation custOrderRel = thisDataSet.Relations.Add("CustOrders",
                thisDataSet.Tables["Customers"].Columns["CustomerID"],
                thisDataSet.Tables["Orders"].Columns["CustomerID"]);




------解决方案--------------------
namespace DataRelation
是这句造成的问题,可改个名字
------解决方案--------------------
哪里有DataRelation 这个类啊,他是命名空间的名字,都不知道custOrderRel 是什么
------解决方案--------------------
哦,2楼说对了,我只关注代码了,没有看到这个问题