Linq Where statements in If conditions VB.net
I am stuck in LINQ where I have to specify the where clauses based upon values of check boxes. I tried searching for answers but most of them are in C# and I am not very good at understanding it's syntax.
Dim recs = From exp In db.exprevs
Where exp.school_id = currentschool.school_id And exp.type = 1
If chbid.IsChecked = True Then
''here I want to tell the query to filter where ID is something
End If
If chbname.IsChecked = True Then
''here I want to filter where name is something
End If
dgsearchresult.ItemsSource = recs
It would be very good if someone guides me how to filter the query further.
.net wpf vb.net linq-to-sql
|
show 4 more comments
I am stuck in LINQ where I have to specify the where clauses based upon values of check boxes. I tried searching for answers but most of them are in C# and I am not very good at understanding it's syntax.
Dim recs = From exp In db.exprevs
Where exp.school_id = currentschool.school_id And exp.type = 1
If chbid.IsChecked = True Then
''here I want to tell the query to filter where ID is something
End If
If chbname.IsChecked = True Then
''here I want to filter where name is something
End If
dgsearchresult.ItemsSource = recs
It would be very good if someone guides me how to filter the query further.
.net wpf vb.net linq-to-sql
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
ANDing multiple conditions together is as simple as chainingWhere
calls on your query, e.g.recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.
– jmcilhinney
Nov 22 '18 at 2:26
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43
|
show 4 more comments
I am stuck in LINQ where I have to specify the where clauses based upon values of check boxes. I tried searching for answers but most of them are in C# and I am not very good at understanding it's syntax.
Dim recs = From exp In db.exprevs
Where exp.school_id = currentschool.school_id And exp.type = 1
If chbid.IsChecked = True Then
''here I want to tell the query to filter where ID is something
End If
If chbname.IsChecked = True Then
''here I want to filter where name is something
End If
dgsearchresult.ItemsSource = recs
It would be very good if someone guides me how to filter the query further.
.net wpf vb.net linq-to-sql
I am stuck in LINQ where I have to specify the where clauses based upon values of check boxes. I tried searching for answers but most of them are in C# and I am not very good at understanding it's syntax.
Dim recs = From exp In db.exprevs
Where exp.school_id = currentschool.school_id And exp.type = 1
If chbid.IsChecked = True Then
''here I want to tell the query to filter where ID is something
End If
If chbname.IsChecked = True Then
''here I want to filter where name is something
End If
dgsearchresult.ItemsSource = recs
It would be very good if someone guides me how to filter the query further.
.net wpf vb.net linq-to-sql
.net wpf vb.net linq-to-sql
edited Nov 22 '18 at 2:03
Abdullah Etizaz
asked Nov 22 '18 at 1:45
Abdullah EtizazAbdullah Etizaz
134
134
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
ANDing multiple conditions together is as simple as chainingWhere
calls on your query, e.g.recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.
– jmcilhinney
Nov 22 '18 at 2:26
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43
|
show 4 more comments
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
ANDing multiple conditions together is as simple as chainingWhere
calls on your query, e.g.recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.
– jmcilhinney
Nov 22 '18 at 2:26
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
ANDing multiple conditions together is as simple as chaining
Where
calls on your query, e.g. recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.– jmcilhinney
Nov 22 '18 at 2:26
ANDing multiple conditions together is as simple as chaining
Where
calls on your query, e.g. recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.– jmcilhinney
Nov 22 '18 at 2:26
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43
|
show 4 more comments
1 Answer
1
active
oldest
votes
Following jmcilhinney's comment on the post I was able to solve my problem. To filter something inside the if statement I had to write this short piece of code in my case.
recs = recs.Where(Function(exp) exp.ID = txtID.text)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53422800%2flinq-where-statements-in-if-conditions-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Following jmcilhinney's comment on the post I was able to solve my problem. To filter something inside the if statement I had to write this short piece of code in my case.
recs = recs.Where(Function(exp) exp.ID = txtID.text)
add a comment |
Following jmcilhinney's comment on the post I was able to solve my problem. To filter something inside the if statement I had to write this short piece of code in my case.
recs = recs.Where(Function(exp) exp.ID = txtID.text)
add a comment |
Following jmcilhinney's comment on the post I was able to solve my problem. To filter something inside the if statement I had to write this short piece of code in my case.
recs = recs.Where(Function(exp) exp.ID = txtID.text)
Following jmcilhinney's comment on the post I was able to solve my problem. To filter something inside the if statement I had to write this short piece of code in my case.
recs = recs.Where(Function(exp) exp.ID = txtID.text)
answered Nov 22 '18 at 2:47
Abdullah EtizazAbdullah Etizaz
134
134
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53422800%2flinq-where-statements-in-if-conditions-vb-net%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
There's not enough info here to help at all. What is the model for exprevs? How do the chbid and chbname even relate to that model? Is chbname checked supposed to over-ride the query of chbid?
– Nathan Champion
Nov 22 '18 at 2:14
ANDing multiple conditions together is as simple as chaining
Where
calls on your query, e.g.recs = recs.Where(Function(exp) exp.ID = someValue)
. You can do that as many times as you like. If you want to OR the conditions then it's not so simple.– jmcilhinney
Nov 22 '18 at 2:26
@jmcilhinney the best I can guess is he's trying to query Where exp.ID = (a textbox?) if chbid is checked and query Where exp.Name = (a textbox?) if chbname is checked. So, that initial query is a waste but there's not enough info.
– Nathan Champion
Nov 22 '18 at 2:40
@jmcilhinney if you would have posted this as an answer I would have accepted it. It worked, I was missing the function(exp) part. Thank You so much.
– Abdullah Etizaz
Nov 22 '18 at 2:42
@NathanChampion Yes that is exactly what I was trying to do.
– Abdullah Etizaz
Nov 22 '18 at 2:43