首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

异常1“DataRelation”是“命名空间”,但此处被当做“类型”来使用

2012-04-07 
错误1“DataRelation”是“命名空间”,但此处被当做“类型”来使用C# code#region using Directivesusing System

错误1“DataRelation”是“命名空间”,但此处被当做“类型”来使用

C# code
#region using Directivesusing System;using System.Data;    //Use ADO.NET namespaceusing System.Data.SqlClient;  //Use SQL Server data provider namespaceusing System.Collections.Generic;using System.Linq;using System.Text;#endregionnamespace 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楼说对了,我只关注代码了,没有看到这个问题

热点排行