C#数据集的错误
我有以下代码:C#数据集的错误
namespace Company.Project.DataProvider
{
partial class MyDataSet
{
partial class MyDataTable
{
}
}
}
namespace Company.Project.DataProvider.MyDataSetTableAdapters
{
public partial class MyTableAdapter
{
public int CommandTimeout
{
set
{
for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
{
if ((this.CommandCollection[i] != null))
{
this.CommandCollection[i].CommandTimeout = value;
}
}
}
}
}
protected void ObjectDataSource1_ObjectCreating
(object sender, ObjectDataSourceEventArgs e)
{
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter =
(Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter)
e.ObjectInstance;
// Set command timeout to 2 minutes
adapter.CommandTimeout = 120;
}
}
当我运行上面的代码,我收到以下错误:
The type or namespace name 'Company' could not be found (are you missing a using directive or an assembly reference?)
什么是错在我的代码?
现在,我收到以下错误。
CS1061: 'CariPeriyot.Rapor.TEST_TumRaporlar' does not contain a definition
for 'CommandCollection' and no extension method 'CommandCollection'
accepting a first argument of type 'CariPeriyot.Rapor.TEST_TumRaporlar'
could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 7: set
Line 8: {
Line 9: for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1))
Line 10: {
Line 11: if ((this.CommandCollection[i] != null))
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter
引用一个类,而不是一个变量,因此分配失败。
尝试:
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter foo = ...
替换下面的代码:
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter =
(Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter)
e.ObjectInstance;
有了:
Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter adapter =
(Company.Project.DataProvider.MyDataSetTableAdapters.MyTableAdapter)
e.ObjectInstance;
哇,正是我所说的,但没有解释... – leppie 2011-05-11 10:54:05
@leppie:但是,我用他的代码的其余部分来找出正确的对象名称:) – 2011-05-11 10:56:47
@leppie:如果你认为这是一个成就回答这样的问题,我会很乐意删除我的答案;) – 2011-05-11 10:57:44
你得到该错误哪条线? – tjrobinson 2011-05-11 10:26:05
它是单个文件吗?同一个项目中的不同文件?不同的库? – abatishchev 2011-05-11 10:50:01
有什么建议吗? – Arbelac 2011-05-14 08:17:20