HighTechTalks DotNet Forums  

% wildcart problem

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss % wildcart problem in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Globetrotter
 
Posts: n/a

Default % wildcart problem - 12-11-2007 , 11:20 AM






I am new to C# and using VS2008 and SQL 2005. For doing some exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country, name);

Problem I have is that the % character behaves like there is one character
at that position while it need to behave like there are zero or more
characters in that position.

For example when I have a country with name USA, US% will show the record
with name USA while U% doesn't show anything. When I preview the data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?


Reply With Quote
  #2  
Old   
William Vaughn
 
Posts: n/a

Default Re: % wildcart problem - 12-11-2007 , 12:38 PM






Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote

Quote:
I am new to C# and using VS2008 and SQL 2005. For doing some exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country, name);

Problem I have is that the % character behaves like there is one character
at that position while it need to behave like there are zero or more
characters in that position.

For example when I have a country with name USA, US% will show the record
with name USA while U% doesn't show anything. When I preview the data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?



Reply With Quote
  #3  
Old   
Globetrotter
 
Posts: n/a

Default Re: % wildcart problem - 12-11-2007 , 01:03 PM



Here it is:

SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL, RecCreatedAt,
RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)

When I execute this query via the query builder, it works correctly.


"William Vaughn" wrote:

Quote:
Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in message
news:5948094F-4BC4-46D5-BD52-867CE4BC6823 (AT) microsoft (DOT) com...
I am new to C# and using VS2008 and SQL 2005. For doing some exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country, name);

Problem I have is that the % character behaves like there is one character
at that position while it need to behave like there are zero or more
characters in that position.

For example when I have a country with name USA, US% will show the record
with name USA while U% doesn't show anything. When I preview the data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?



Reply With Quote
  #4  
Old   
Globetrotter
 
Posts: n/a

Default Re: % wildcart problem - 12-11-2007 , 03:55 PM



I have seen somewhere else in this newsgroup that you can use the SQL
profiler. This is what is the query:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nchar(50)',@Name=N'ne%

"Globetrotter" wrote:

Quote:
Here it is:

SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL, RecCreatedAt,
RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)

When I execute this query via the query builder, it works correctly.


"William Vaughn" wrote:

Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in message
news:5948094F-4BC4-46D5-BD52-867CE4BC6823 (AT) microsoft (DOT) com...
I am new to C# and using VS2008 and SQL 2005. For doing some exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country, name);

Problem I have is that the % character behaves like there is one character
at that position while it need to behave like there are zero or more
characters in that position.

For example when I have a country with name USA, US% will show the record
with name USA while U% doesn't show anything. When I preview the data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?



Reply With Quote
  #5  
Old   
Globetrotter
 
Posts: n/a

Default Re: % wildcart problem - 12-12-2007 , 04:02 AM



I have used SQL profiler with a query direct from the Query Builder. The
result was:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nvarchar(50)',@Name=N'ne%

The difference is the nchar(50) and nvarchar(50) type in both queries. I
have now changed the type to nvarchar(50) in the SQL table and it works now
correctly. However I still don't understand why it didn't work with the
nchar(50) type. Does anybody know that?


"Globetrotter" wrote:

Quote:
I have seen somewhere else in this newsgroup that you can use the SQL
profiler. This is what is the query:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nchar(50)',@Name=N'ne%

"Globetrotter" wrote:

Here it is:

SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL, RecCreatedAt,
RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)

When I execute this query via the query builder, it works correctly.


"William Vaughn" wrote:

Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in message
news:5948094F-4BC4-46D5-BD52-867CE4BC6823 (AT) microsoft (DOT) com...
I am new to C# and using VS2008 and SQL 2005. For doing some exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country, name);

Problem I have is that the % character behaves like there is one character
at that position while it need to behave like there are zero or more
characters in that position.

For example when I have a country with name USA, US% will show the record
with name USA while U% doesn't show anything. When I preview the data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?



Reply With Quote
  #6  
Old   
William Vaughn
 
Posts: n/a

Default Re: % wildcart problem - 12-12-2007 , 12:34 PM



Ah, yes. When a comparison is made to a Char type and the length of the
right-hand side of the expression does not match the char length, the
comparison always fails. I rarely use Char for this reason.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote

Quote:
I have used SQL profiler with a query direct from the Query Builder. The
result was:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name,
NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nvarchar(50)',@Name=N'ne%

The difference is the nchar(50) and nvarchar(50) type in both queries. I
have now changed the type to nvarchar(50) in the SQL table and it works
now
correctly. However I still don't understand why it didn't work with the
nchar(50) type. Does anybody know that?


"Globetrotter" wrote:

I have seen somewhere else in this newsgroup that you can use the SQL
profiler. This is what is the query:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name,
NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nchar(50)',@Name=N'ne%

"Globetrotter" wrote:

Here it is:

SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL, RecCreatedAt,
RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)

When I execute this query via the query builder, it works correctly.


"William Vaughn" wrote:

Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in
message
news:5948094F-4BC4-46D5-BD52-867CE4BC6823 (AT) microsoft (DOT) com...
I am new to C# and using VS2008 and SQL 2005. For doing some
exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country,
name);

Problem I have is that the % character behaves like there is one
character
at that position while it need to behave like there are zero or
more
characters in that position.

For example when I have a country with name USA, US% will show the
record
with name USA while U% doesn't show anything. When I preview the
data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?




Reply With Quote
  #7  
Old   
Globetrotter
 
Posts: n/a

Default Re: % wildcart problem - 12-12-2007 , 04:09 PM



Thanks for your answers William!

"William Vaughn" wrote:

Quote:
Ah, yes. When a comparison is made to a Char type and the length of the
right-hand side of the expression does not match the char length, the
comparison always fails. I rarely use Char for this reason.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in message
news:0BC08D5F-47D6-4910-8F31-D308D5A3CF7C (AT) microsoft (DOT) com...
I have used SQL profiler with a query direct from the Query Builder. The
result was:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name,
NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nvarchar(50)',@Name=N'ne%

The difference is the nchar(50) and nvarchar(50) type in both queries. I
have now changed the type to nvarchar(50) in the SQL table and it works
now
correctly. However I still don't understand why it didn't work with the
nchar(50) type. Does anybody know that?


"Globetrotter" wrote:

I have seen somewhere else in this newsgroup that you can use the SQL
profiler. This is what is the query:
exec sp_executesql N'SELECT PkCountryId, Flag, CodeA2, CodeA3, Name,
NameNL,
RecCreatedAt, RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)',N'@Name nchar(50)',@Name=N'ne%

"Globetrotter" wrote:

Here it is:

SELECT PkCountryId, Flag, CodeA2, CodeA3, Name, NameNL, RecCreatedAt,
RecUpdatedAt, RecCreatedBy, RecUpdatedBy
FROM Country
WHERE (Name LIKE @Name)

When I execute this query via the query builder, it works correctly.


"William Vaughn" wrote:

Let's see the TableAdapter FillBy query.

--
__________________________________________________ ________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
__________________________________________________ __________________________________________
"Globetrotter" <Globetrotter (AT) discussions (DOT) microsoft.com> wrote in
message
news:5948094F-4BC4-46D5-BD52-867CE4BC6823 (AT) microsoft (DOT) com...
I am new to C# and using VS2008 and SQL 2005. For doing some
exercises I
have made the following code:

string name = tstxtName.Text + "%";
this.taCountry.FillByName(this.dsTest.Country,
name);

Problem I have is that the % character behaves like there is one
character
at that position while it need to behave like there are zero or
more
characters in that position.

For example when I have a country with name USA, US% will show the
record
with name USA while U% doesn't show anything. When I preview the
data
directly within the Query Builder of VS2008, it works perfect.

Has anybody an idea what can be the problem?




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.