DataTable.Select Method bug?

A

Adrian

Hi all

..Net Framework 1.1
vb.net

We use the Select-Method of the DataTable class to retriev data. The select
statement is as follows:

myDeDT.Select("Pers_Name = 'Adrian '")

Please look exactly at the content of the parameter! There is a space at the
end of Adrian included! This must be like this, because the data is stored
in the database in this way.
This field Pers_Name is not a primary key field.

Now we assume that we have two rows in the datatable with the following
values in the Pers_Name field:
Row 1: 'Adrian'
Row 2: 'Adrian '

One with the space at the end, and one without.

With the DataTable.Select-Method we receive now both rows as result! Why?
Is this a bug? Can i set somewhere a property to tell the DataTable that he
should not remove spaces from the parameter values?

Thank you for your help
Adrian

Please remove NOSPAM from my reply email address.
 
P

Patrice

Interesting...

It looks like something I noticed once for a SQL database (not sure if this
the norm or not) with trailing blanks in varchar not being taken into
account... It could also have been done to ease using CHAR columns...

Describing what you are trying to do may help to find a workaround (for
example you could remove duplicates server side) if .NET doesn't provide
one.
 
A

Adrian

Hello Patrice

Thank you for your answer.

These fields are cofingured as of type nvarchar with size 25. And if i test
it with sql server enterprise manager, then i can add a trailing blank at
the end of a field.

But if i use the described DataTable.Select-Method then this select Method
ignores the trailing blanks. Why?

What I'm trying to do is to select rows with the DataTable.Select-Method
from a datatable in SQL Server 2000 with vb.net, ado.net and the .net
framework 1.1 and that this stupid Select-Method don't ignore trailing
blanks in the select statement as in myDeDT.Select("Pers_Name = 'Adrian '")
where a trailing blank is included. The result of this are actual 2 Rows,
where one Row contains 'Adrian' in Pers_Name (without trailing blank) and
one row contains 'Adrian ' (with trailing blank), but I want only the row
that exactly matchs the Select-Criteria. That means the row with 'Adrian '
(the trainling blank included).
Thats all.
It seems to me, that I don't wanna do something complicated or abnormal, or?
Due to the user data this behaviour must be used. We cannot trim the data
before saving it to the database.

Do you have some ideas Patrice?

Thanks
Adrian
 

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

Top