How to read 2 commands without closing the first one?How does database indexing work?How can I prevent SQL injection in PHP?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I UPDATE from a SELECT in SQL Server?How do I generate a random int number?Select first row in each GROUP BY group?There is already an open DataReader associated with this Command which must be closed firstHow to import an SQL file using the command line in MySQL?

Does the fact that we can only measure the two-way speed of light undermine the axiom of invariance?

Why is this integration method not valid?

Computing elements of a 1000 x 60 matrix exhausts RAM

How to tease a romance without a cat and mouse chase?

How do I write real-world stories separate from my country of origin?

nginx conf: http2 module not working in Chrome in ubuntu 18.04

Are clauses with "который" restrictive or non-restrictive by default?

Is it normal to "extract a paper" from a master thesis?

why "American-born", not "America-born"?

How to make Flex Markers appear in Logic Pro X?

mmap: effect of other processes writing to a file previously mapped read-only

Is being an extrovert a necessary condition to be a manager?

How could Dwarves prevent sand from filling up their settlements

Proto-Indo-European (PIE) words with IPA

How would a physicist explain this starship engine?

Why is 'additive' EQ more difficult to use than 'subtractive'?

Is the default 512 byte physical sector size appropriate for SSD disks under Linux?

Why do testers need root cause analysis?

(For training purposes) Are there any openings with rook pawns that are more effective than others (and if so, what are they)?

Surface of the 3x3x3 cube as a graph

Efficient Algorithms for Destroyed Document Reconstruction

A nasty indefinite integral

Passport queue length in UK in relation to arrival method

Find this Unique UVC Palindrome ( ignoring signs and decimal) from Given Fractional Relationship



How to read 2 commands without closing the first one?


How does database indexing work?How can I prevent SQL injection in PHP?How do I enumerate an enum in C#?How to create Excel (.XLS and .XLSX) file in C# without installing Ms Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I UPDATE from a SELECT in SQL Server?How do I generate a random int number?Select first row in each GROUP BY group?There is already an open DataReader associated with this Command which must be closed firstHow to import an SQL file using the command line in MySQL?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















i know the question seems a bit weird but ive looked at many videos,codes and still i couldnt find any solution. I am trying to check if username or email is taken or not.But i want to check them seperately.First username and secondly email. I am kinda beginner so i dont know the code i wrote is proper but this is what i coded. and it is also in a if-else statement like this.



http://prntscr.com/n1zzao



so how can i do this ? how can i read 2 sql commands without closing the first one ?










share|improve this question






















  • Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

    – Patrick Artner
    Mar 23 at 20:56






  • 2





    Use a Stored Procedure and btw STOP posting code as image

    – Rahul
    Mar 23 at 20:56






  • 1





    idownvotedbecau.se/imageofcode

    – Patrick Artner
    Mar 23 at 20:56

















-2















i know the question seems a bit weird but ive looked at many videos,codes and still i couldnt find any solution. I am trying to check if username or email is taken or not.But i want to check them seperately.First username and secondly email. I am kinda beginner so i dont know the code i wrote is proper but this is what i coded. and it is also in a if-else statement like this.



http://prntscr.com/n1zzao



so how can i do this ? how can i read 2 sql commands without closing the first one ?










share|improve this question






















  • Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

    – Patrick Artner
    Mar 23 at 20:56






  • 2





    Use a Stored Procedure and btw STOP posting code as image

    – Rahul
    Mar 23 at 20:56






  • 1





    idownvotedbecau.se/imageofcode

    – Patrick Artner
    Mar 23 at 20:56













-2












-2








-2


0






i know the question seems a bit weird but ive looked at many videos,codes and still i couldnt find any solution. I am trying to check if username or email is taken or not.But i want to check them seperately.First username and secondly email. I am kinda beginner so i dont know the code i wrote is proper but this is what i coded. and it is also in a if-else statement like this.



http://prntscr.com/n1zzao



so how can i do this ? how can i read 2 sql commands without closing the first one ?










share|improve this question














i know the question seems a bit weird but ive looked at many videos,codes and still i couldnt find any solution. I am trying to check if username or email is taken or not.But i want to check them seperately.First username and secondly email. I am kinda beginner so i dont know the code i wrote is proper but this is what i coded. and it is also in a if-else statement like this.



http://prntscr.com/n1zzao



so how can i do this ? how can i read 2 sql commands without closing the first one ?







c# sql ado.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 20:54









mryellow61mryellow61

12




12












  • Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

    – Patrick Artner
    Mar 23 at 20:56






  • 2





    Use a Stored Procedure and btw STOP posting code as image

    – Rahul
    Mar 23 at 20:56






  • 1





    idownvotedbecau.se/imageofcode

    – Patrick Artner
    Mar 23 at 20:56

















  • Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

    – Patrick Artner
    Mar 23 at 20:56






  • 2





    Use a Stored Procedure and btw STOP posting code as image

    – Rahul
    Mar 23 at 20:56






  • 1





    idownvotedbecau.se/imageofcode

    – Patrick Artner
    Mar 23 at 20:56
















Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

– Patrick Artner
Mar 23 at 20:56





Please see the How to Ask help page and The perfect question blog post by Jon Skeet. We won't know how to make the changes to your existing code base without seeing your original code. Please post a Minimal, Complete, and Verifiable example, and fully explain what needs to be modified.

– Patrick Artner
Mar 23 at 20:56




2




2





Use a Stored Procedure and btw STOP posting code as image

– Rahul
Mar 23 at 20:56





Use a Stored Procedure and btw STOP posting code as image

– Rahul
Mar 23 at 20:56




1




1





idownvotedbecau.se/imageofcode

– Patrick Artner
Mar 23 at 20:56





idownvotedbecau.se/imageofcode

– Patrick Artner
Mar 23 at 20:56












2 Answers
2






active

oldest

votes


















0














// Check if username is taken
var command = new SqlCommand("SELECT * FROM YourTable WHERE userName=" userName ,
yourConnection);
var reader = command.ExecuteReader();

// Check if email is taken
var command = new SqlCommand("SELECT * FROM YourTable WHERE email=" email,
yourConnection)
command.ExecuteNonQuery();





share|improve this answer























  • i am doing it in if else statement block so this doesnt help

    – mryellow61
    Mar 24 at 11:32



















0














Firstly, I am not sure why are you insisting on having to find the result in two separate queries and that too without closing command for first one (if that is what you mean by 'without closing the first one') while executing the second.



To me, it seems you would like to know if the name and email already exist in the database, if so are they taken by same person (found on the same record in db) or by different persons (found on different records).



You could achieve this by following one single query. You may get multiple records back and for every record the third column match_type will clarify the type.



select kullaniciAdi, [Mail Adresi], 'BOTH' as match_type from kullanicilar 
where kullaniciAdi = '<username text>' and [Mail Adresi] = '<mail address text>'
union
select kullaniciAdi, [Mail Adresi], 'ONLY_USER' as match_type from kullanicilar
where kullaniciAdi = '<username text>' and [Mail Adresi] <> '<mail address text>'
union
select kullaniciAdi, [Mail Adresi], 'ONLY_MAIL' as match_type from kullanicilar
where kullaniciAdi <> '<username text>' and [Mail Adresi] = '<mail address text>'


Note Table and / or column names in query may have typos as it is error prone to type having looked at image.






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%2f55318275%2fhow-to-read-2-commands-without-closing-the-first-one%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    // Check if username is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE userName=" userName ,
    yourConnection);
    var reader = command.ExecuteReader();

    // Check if email is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE email=" email,
    yourConnection)
    command.ExecuteNonQuery();





    share|improve this answer























    • i am doing it in if else statement block so this doesnt help

      – mryellow61
      Mar 24 at 11:32
















    0














    // Check if username is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE userName=" userName ,
    yourConnection);
    var reader = command.ExecuteReader();

    // Check if email is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE email=" email,
    yourConnection)
    command.ExecuteNonQuery();





    share|improve this answer























    • i am doing it in if else statement block so this doesnt help

      – mryellow61
      Mar 24 at 11:32














    0












    0








    0







    // Check if username is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE userName=" userName ,
    yourConnection);
    var reader = command.ExecuteReader();

    // Check if email is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE email=" email,
    yourConnection)
    command.ExecuteNonQuery();





    share|improve this answer













    // Check if username is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE userName=" userName ,
    yourConnection);
    var reader = command.ExecuteReader();

    // Check if email is taken
    var command = new SqlCommand("SELECT * FROM YourTable WHERE email=" email,
    yourConnection)
    command.ExecuteNonQuery();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 23 at 21:01









    Nestor EduardoNestor Eduardo

    11




    11












    • i am doing it in if else statement block so this doesnt help

      – mryellow61
      Mar 24 at 11:32


















    • i am doing it in if else statement block so this doesnt help

      – mryellow61
      Mar 24 at 11:32

















    i am doing it in if else statement block so this doesnt help

    – mryellow61
    Mar 24 at 11:32






    i am doing it in if else statement block so this doesnt help

    – mryellow61
    Mar 24 at 11:32














    0














    Firstly, I am not sure why are you insisting on having to find the result in two separate queries and that too without closing command for first one (if that is what you mean by 'without closing the first one') while executing the second.



    To me, it seems you would like to know if the name and email already exist in the database, if so are they taken by same person (found on the same record in db) or by different persons (found on different records).



    You could achieve this by following one single query. You may get multiple records back and for every record the third column match_type will clarify the type.



    select kullaniciAdi, [Mail Adresi], 'BOTH' as match_type from kullanicilar 
    where kullaniciAdi = '<username text>' and [Mail Adresi] = '<mail address text>'
    union
    select kullaniciAdi, [Mail Adresi], 'ONLY_USER' as match_type from kullanicilar
    where kullaniciAdi = '<username text>' and [Mail Adresi] <> '<mail address text>'
    union
    select kullaniciAdi, [Mail Adresi], 'ONLY_MAIL' as match_type from kullanicilar
    where kullaniciAdi <> '<username text>' and [Mail Adresi] = '<mail address text>'


    Note Table and / or column names in query may have typos as it is error prone to type having looked at image.






    share|improve this answer



























      0














      Firstly, I am not sure why are you insisting on having to find the result in two separate queries and that too without closing command for first one (if that is what you mean by 'without closing the first one') while executing the second.



      To me, it seems you would like to know if the name and email already exist in the database, if so are they taken by same person (found on the same record in db) or by different persons (found on different records).



      You could achieve this by following one single query. You may get multiple records back and for every record the third column match_type will clarify the type.



      select kullaniciAdi, [Mail Adresi], 'BOTH' as match_type from kullanicilar 
      where kullaniciAdi = '<username text>' and [Mail Adresi] = '<mail address text>'
      union
      select kullaniciAdi, [Mail Adresi], 'ONLY_USER' as match_type from kullanicilar
      where kullaniciAdi = '<username text>' and [Mail Adresi] <> '<mail address text>'
      union
      select kullaniciAdi, [Mail Adresi], 'ONLY_MAIL' as match_type from kullanicilar
      where kullaniciAdi <> '<username text>' and [Mail Adresi] = '<mail address text>'


      Note Table and / or column names in query may have typos as it is error prone to type having looked at image.






      share|improve this answer

























        0












        0








        0







        Firstly, I am not sure why are you insisting on having to find the result in two separate queries and that too without closing command for first one (if that is what you mean by 'without closing the first one') while executing the second.



        To me, it seems you would like to know if the name and email already exist in the database, if so are they taken by same person (found on the same record in db) or by different persons (found on different records).



        You could achieve this by following one single query. You may get multiple records back and for every record the third column match_type will clarify the type.



        select kullaniciAdi, [Mail Adresi], 'BOTH' as match_type from kullanicilar 
        where kullaniciAdi = '<username text>' and [Mail Adresi] = '<mail address text>'
        union
        select kullaniciAdi, [Mail Adresi], 'ONLY_USER' as match_type from kullanicilar
        where kullaniciAdi = '<username text>' and [Mail Adresi] <> '<mail address text>'
        union
        select kullaniciAdi, [Mail Adresi], 'ONLY_MAIL' as match_type from kullanicilar
        where kullaniciAdi <> '<username text>' and [Mail Adresi] = '<mail address text>'


        Note Table and / or column names in query may have typos as it is error prone to type having looked at image.






        share|improve this answer













        Firstly, I am not sure why are you insisting on having to find the result in two separate queries and that too without closing command for first one (if that is what you mean by 'without closing the first one') while executing the second.



        To me, it seems you would like to know if the name and email already exist in the database, if so are they taken by same person (found on the same record in db) or by different persons (found on different records).



        You could achieve this by following one single query. You may get multiple records back and for every record the third column match_type will clarify the type.



        select kullaniciAdi, [Mail Adresi], 'BOTH' as match_type from kullanicilar 
        where kullaniciAdi = '<username text>' and [Mail Adresi] = '<mail address text>'
        union
        select kullaniciAdi, [Mail Adresi], 'ONLY_USER' as match_type from kullanicilar
        where kullaniciAdi = '<username text>' and [Mail Adresi] <> '<mail address text>'
        union
        select kullaniciAdi, [Mail Adresi], 'ONLY_MAIL' as match_type from kullanicilar
        where kullaniciAdi <> '<username text>' and [Mail Adresi] = '<mail address text>'


        Note Table and / or column names in query may have typos as it is error prone to type having looked at image.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 0:33









        GroGro

        50549




        50549



























            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%2f55318275%2fhow-to-read-2-commands-without-closing-the-first-one%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현