DataTable select criteria with single quotes and without
up vote
-1
down vote
favorite
I have a DataTable dt with Column RefNum. There is a row with RefNum = 293
when i try to retrieve value using dt.Select("RefNum = 293")
i get no result , but when i wrap number into single quotes dt.Select("RefNum = '293'")
i get result
Could someone explain , how it works ?
other values are fine to read
in database column RefNum is a nvarchar column
c# winforms datatable
add a comment |
up vote
-1
down vote
favorite
I have a DataTable dt with Column RefNum. There is a row with RefNum = 293
when i try to retrieve value using dt.Select("RefNum = 293")
i get no result , but when i wrap number into single quotes dt.Select("RefNum = '293'")
i get result
Could someone explain , how it works ?
other values are fine to read
in database column RefNum is a nvarchar column
c# winforms datatable
2
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Z.R.T. Thenvarchar
is string in SQL.
– S.Akbari
Nov 8 at 13:35
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
1
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will bestring
notnvarchar
. The comparison will follow .NET rules, where comparing objects of different types isfalse
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type
– Panagiotis Kanavos
Nov 8 at 14:01
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a DataTable dt with Column RefNum. There is a row with RefNum = 293
when i try to retrieve value using dt.Select("RefNum = 293")
i get no result , but when i wrap number into single quotes dt.Select("RefNum = '293'")
i get result
Could someone explain , how it works ?
other values are fine to read
in database column RefNum is a nvarchar column
c# winforms datatable
I have a DataTable dt with Column RefNum. There is a row with RefNum = 293
when i try to retrieve value using dt.Select("RefNum = 293")
i get no result , but when i wrap number into single quotes dt.Select("RefNum = '293'")
i get result
Could someone explain , how it works ?
other values are fine to read
in database column RefNum is a nvarchar column
c# winforms datatable
c# winforms datatable
edited Nov 8 at 13:28
asked Nov 8 at 13:21
Z.R.T.
1,026511
1,026511
2
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Z.R.T. Thenvarchar
is string in SQL.
– S.Akbari
Nov 8 at 13:35
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
1
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will bestring
notnvarchar
. The comparison will follow .NET rules, where comparing objects of different types isfalse
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type
– Panagiotis Kanavos
Nov 8 at 14:01
add a comment |
2
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Z.R.T. Thenvarchar
is string in SQL.
– S.Akbari
Nov 8 at 13:35
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
1
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will bestring
notnvarchar
. The comparison will follow .NET rules, where comparing objects of different types isfalse
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type
– Panagiotis Kanavos
Nov 8 at 14:01
2
2
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Z.R.T. The
nvarchar
is string in SQL.– S.Akbari
Nov 8 at 13:35
@Z.R.T. The
nvarchar
is string in SQL.– S.Akbari
Nov 8 at 13:35
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
1
1
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will be
string
not nvarchar
. The comparison will follow .NET rules, where comparing objects of different types is false
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type– Panagiotis Kanavos
Nov 8 at 14:01
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will be
string
not nvarchar
. The comparison will follow .NET rules, where comparing objects of different types is false
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type– Panagiotis Kanavos
Nov 8 at 14:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
It's very weird that you get results on other tables when searching on string values without quotes. Are you certain these are not numeric columns?
According to docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter
and www.csharp-examples.net/dataview-rowfilter, filtering on string values/columns requires single quotes.
So I think you better play it safe and use the single quotes.. :-)
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
It's very weird that you get results on other tables when searching on string values without quotes. Are you certain these are not numeric columns?
According to docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter
and www.csharp-examples.net/dataview-rowfilter, filtering on string values/columns requires single quotes.
So I think you better play it safe and use the single quotes.. :-)
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
add a comment |
up vote
0
down vote
It's very weird that you get results on other tables when searching on string values without quotes. Are you certain these are not numeric columns?
According to docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter
and www.csharp-examples.net/dataview-rowfilter, filtering on string values/columns requires single quotes.
So I think you better play it safe and use the single quotes.. :-)
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
add a comment |
up vote
0
down vote
up vote
0
down vote
It's very weird that you get results on other tables when searching on string values without quotes. Are you certain these are not numeric columns?
According to docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter
and www.csharp-examples.net/dataview-rowfilter, filtering on string values/columns requires single quotes.
So I think you better play it safe and use the single quotes.. :-)
It's very weird that you get results on other tables when searching on string values without quotes. Are you certain these are not numeric columns?
According to docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter
and www.csharp-examples.net/dataview-rowfilter, filtering on string values/columns requires single quotes.
So I think you better play it safe and use the single quotes.. :-)
answered Nov 8 at 13:45
johey
11410
11410
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
add a comment |
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
PS: I cannot see your images, they are blocked by my company's firewall.
– johey
Nov 8 at 13:46
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
those aren't images, it's the Microsoft documentation site. If you can't read the docs, you can't write or fix code
– Panagiotis Kanavos
Nov 8 at 13:59
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208625%2fdatatable-select-criteria-with-single-quotes-and-without%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Sounds like the data type of RefNum is a string type.
– Crowcoder
Nov 8 at 13:23
@Crowcoder RefNum is nvarchar , but so far others values can be read without quotes . How it possible ?
– Z.R.T.
Nov 8 at 13:34
@Z.R.T. The
nvarchar
is string in SQL.– S.Akbari
Nov 8 at 13:35
@S.Akbari agree , but how some values from the same column can be retrieved without quotes but others can't. How can you explain different behavior on the pic ?
– Z.R.T.
Nov 8 at 13:38
1
@Z.R.T. if the behaviour is different, it means the types are different. DataTable objects are .NET objects. The column's type will be
string
notnvarchar
. The comparison will follow .NET rules, where comparing objects of different types isfalse
by default. In SQL though, one type is implicitly converted into another and the values compared as if they were the same type– Panagiotis Kanavos
Nov 8 at 14:01