Can´t Find row value in dataview. Strange error.

  • Thread starter Thread starter Ibai Peña
  • Start date Start date
I

Ibai Peña

Hi,

I´m trying to find a row in a dataview. First I define a PrimaryKey to the
DataTable and then try to find a value, but gives me this error:

An unhandled exception of type 'System.ArgumentException' occurred in
System.Data.dll
Additional information: Expecting 0 value(s) for the key being indexed, but
received 1 value(s).

Here is some the code that I use:

DataColumn[] keys = new DataColumn[1];
keys[0] = TInventario.Columns["codigoart"];
TInventario.PrimaryKey = keys;
VInventario = TInventario.DefaultView;

string temp = (string)TempRow[0];
int Seleccionado = VInventario.Find((object)temp);

I have tried VInventario.Find(temp); too without succed

What am I doing wrong?
thanks in advance,
 
It is a string row.

--
Ibai Peña

Alex Feinman said:
What kind of data do you have in the key column?

Ibai Peña said:
Hi,

I´m trying to find a row in a dataview. First I define a PrimaryKey to the
DataTable and then try to find a value, but gives me this error:

An unhandled exception of type 'System.ArgumentException' occurred in
System.Data.dll
Additional information: Expecting 0 value(s) for the key being indexed, but
received 1 value(s).

Here is some the code that I use:

DataColumn[] keys = new DataColumn[1];
keys[0] = TInventario.Columns["codigoart"];
TInventario.PrimaryKey = keys;
VInventario = TInventario.DefaultView;

string temp = (string)TempRow[0];
int Seleccionado = VInventario.Find((object)temp);

I have tried VInventario.Find(temp); too without succed

What am I doing wrong?
thanks in advance,
 
You should define Sort for DataView in order to create index for Find
function.

VInventario.Sort = "codigoart";
string temp = (string)TempRow[0];
int Seleccionado = VInventario.Find((object)temp);
 
Yes, that was the problem.

Thank you
--
Ibai Pena
Igor Zhavrid said:
You should define Sort for DataView in order to create index for Find
function.

VInventario.Sort = "codigoart";
string temp = (string)TempRow[0];
int Seleccionado = VInventario.Find((object)temp);


Ibai Peña said:
Hi,

I´m trying to find a row in a dataview. First I define a PrimaryKey to the
DataTable and then try to find a value, but gives me this error:

An unhandled exception of type 'System.ArgumentException' occurred in
System.Data.dll
Additional information: Expecting 0 value(s) for the key being indexed, but
received 1 value(s).

Here is some the code that I use:

DataColumn[] keys = new DataColumn[1];
keys[0] = TInventario.Columns["codigoart"];
TInventario.PrimaryKey = keys;
VInventario = TInventario.DefaultView;

string temp = (string)TempRow[0];
int Seleccionado = VInventario.Find((object)temp);

I have tried VInventario.Find(temp); too without succed

What am I doing wrong?
thanks in advance,
 
Back
Top