strange exception with datatable

M

mathieu

I have a class deriving from datatable. In ctor i define the columns
and set the pk. And there it crashes on the unique = true line.

public DTNomenclatureLevel() : DataTable
{
try
{
Columns.Clear();

base.Columns.AddRange(new DataColumn[] {new DataColumn("Id",
System.Type.GetType("System.Int32")), new DataColumn("Lib",
System.Type.GetType("System.String"))} );


//PK (Id)
base.Columns[0].Unique = true;
base.PrimaryKey = new DataColumn[]{base.Columns[0]};
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}

What is strange is that it's was working well up to this morning ???

here is the error message:

System.Object {System.NullReferenceException} System.Object
StackTrace " at System.Data.DataTable.GetIndex(Int32[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)\r\n at
System.Data.DataColumn.get_SortIndex()\r\n at
System.Data.DataColumn.CheckUnique()\r\n at
System.Data.DataColumn.set_Unique(Boolean value)\r\n at
TNS.AdRequest.Core.DTNomenclatureLevel..ctor

Anyone have a clue?
thanks
mat
 
M

Miha Markic [MVP C#]

Hi,

Works for me.
Are you sure that the error is there?
Can you creata a repro sample?
 
M

mathieu

Thanks for your response but i found what was going wrong.
I had override (well new) the Reset Function of DataTable and was not calling
base.Reset in it.

....And the constructor is calling this function.

So watch out folks :)

but thanks anyway.
mathieu

Miha Markic said:
Hi,

Works for me.
Are you sure that the error is there?
Can you creata a repro sample?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

mathieu said:
I have a class deriving from datatable. In ctor i define the columns
and set the pk. And there it crashes on the unique = true line.

public DTNomenclatureLevel() : DataTable
{
try
{
Columns.Clear();

base.Columns.AddRange(new DataColumn[] {new DataColumn("Id",
System.Type.GetType("System.Int32")), new DataColumn("Lib",
System.Type.GetType("System.String"))} );


//PK (Id)
base.Columns[0].Unique = true;
base.PrimaryKey = new DataColumn[]{base.Columns[0]};
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}

What is strange is that it's was working well up to this morning ???

here is the error message:

System.Object {System.NullReferenceException} System.Object
StackTrace " at System.Data.DataTable.GetIndex(Int32[] indexDesc,
DataViewRowState recordStates, IFilter rowFilter)\r\n at
System.Data.DataColumn.get_SortIndex()\r\n at
System.Data.DataColumn.CheckUnique()\r\n at
System.Data.DataColumn.set_Unique(Boolean value)\r\n at
TNS.AdRequest.Core.DTNomenclatureLevel..ctor

Anyone have a clue?
thanks
mat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top