![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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? |
#3
| |||
| |||
|
|
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? |
#4
| |||
| |||
|
|
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? |
#5
| |||
| |||
|
|
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? |
#6
| |||
| |||
|
|
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? |
#7
| |||
| |||
|
|
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? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |