Linq Where statements in If conditions VB.net












0















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.










share|improve this question

























  • 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
















0















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.










share|improve this question

























  • 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















0














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)





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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)





    share|improve this answer




























      0














      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)





      share|improve this answer


























        0












        0








        0







        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)





        share|improve this answer













        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)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 2:47









        Abdullah EtizazAbdullah Etizaz

        134




        134
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory