How to select certain table in my database












0















I'm currently using OleDB.



My problem is I can't select my table when searching it using textbox.



This is my code:



OleDbCommand inv = new OleDbCommand("Select [Part Number], [Part Name], [Ordered Quantity], [Arrived Quantity] From '"+textBox1.Text+"%'", PartsDB);
OleDbDataAdapter adapt = new OleDbDataAdapter(inv);
DataTable dt = new DataTable();
adapt.Fill(dt);
dataGridView2.DataSource = dt;









share|improve this question




















  • 1





    This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

    – MatBailie
    Nov 21 '18 at 8:03











  • Also: which programming language is that?

    – a_horse_with_no_name
    Nov 23 '18 at 9:07
















0















I'm currently using OleDB.



My problem is I can't select my table when searching it using textbox.



This is my code:



OleDbCommand inv = new OleDbCommand("Select [Part Number], [Part Name], [Ordered Quantity], [Arrived Quantity] From '"+textBox1.Text+"%'", PartsDB);
OleDbDataAdapter adapt = new OleDbDataAdapter(inv);
DataTable dt = new DataTable();
adapt.Fill(dt);
dataGridView2.DataSource = dt;









share|improve this question




















  • 1





    This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

    – MatBailie
    Nov 21 '18 at 8:03











  • Also: which programming language is that?

    – a_horse_with_no_name
    Nov 23 '18 at 9:07














0












0








0








I'm currently using OleDB.



My problem is I can't select my table when searching it using textbox.



This is my code:



OleDbCommand inv = new OleDbCommand("Select [Part Number], [Part Name], [Ordered Quantity], [Arrived Quantity] From '"+textBox1.Text+"%'", PartsDB);
OleDbDataAdapter adapt = new OleDbDataAdapter(inv);
DataTable dt = new DataTable();
adapt.Fill(dt);
dataGridView2.DataSource = dt;









share|improve this question
















I'm currently using OleDB.



My problem is I can't select my table when searching it using textbox.



This is my code:



OleDbCommand inv = new OleDbCommand("Select [Part Number], [Part Name], [Ordered Quantity], [Arrived Quantity] From '"+textBox1.Text+"%'", PartsDB);
OleDbDataAdapter adapt = new OleDbDataAdapter(inv);
DataTable dt = new DataTable();
adapt.Fill(dt);
dataGridView2.DataSource = dt;






sql database select oledb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:37









Ciarán

2,65211015




2,65211015










asked Nov 21 '18 at 4:42









Jed TurquezaJed Turqueza

1




1








  • 1





    This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

    – MatBailie
    Nov 21 '18 at 8:03











  • Also: which programming language is that?

    – a_horse_with_no_name
    Nov 23 '18 at 9:07














  • 1





    This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

    – MatBailie
    Nov 21 '18 at 8:03











  • Also: which programming language is that?

    – a_horse_with_no_name
    Nov 23 '18 at 9:07








1




1





This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

– MatBailie
Nov 21 '18 at 8:03





This is a SQL Injection Vulnerability, don't do this. Which database are you using? MYSQL, SQL SERVER, Oracle, etc?

– MatBailie
Nov 21 '18 at 8:03













Also: which programming language is that?

– a_horse_with_no_name
Nov 23 '18 at 9:07





Also: which programming language is that?

– a_horse_with_no_name
Nov 23 '18 at 9:07












2 Answers
2






active

oldest

votes


















0














SQL Injection concerns aside this is not valid SQL. You are trying to make your table name 1) a string and 2) wild carded. This is not supported by any variant of SQL that I am aware of.



i.e.



Select column1, column2 From 'Tablename%'


is not valid SQL. You must say...



Select column1, column2 From Tablename


where Tablename exists as a table in your database






share|improve this answer

































    0














    What is it that makes you have several distinct tables in your database that you should be able to do that same SELECT from ?



    In principle, if you have that situation, then there must be some information element that distinguishes those tables from one another, and the intent of the relational model is for such tables to be combined into one, with the distinguishing element included as an additional attribute (/column).






    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%2f53405383%2fhow-to-select-certain-table-in-my-database%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














      SQL Injection concerns aside this is not valid SQL. You are trying to make your table name 1) a string and 2) wild carded. This is not supported by any variant of SQL that I am aware of.



      i.e.



      Select column1, column2 From 'Tablename%'


      is not valid SQL. You must say...



      Select column1, column2 From Tablename


      where Tablename exists as a table in your database






      share|improve this answer






























        0














        SQL Injection concerns aside this is not valid SQL. You are trying to make your table name 1) a string and 2) wild carded. This is not supported by any variant of SQL that I am aware of.



        i.e.



        Select column1, column2 From 'Tablename%'


        is not valid SQL. You must say...



        Select column1, column2 From Tablename


        where Tablename exists as a table in your database






        share|improve this answer




























          0












          0








          0







          SQL Injection concerns aside this is not valid SQL. You are trying to make your table name 1) a string and 2) wild carded. This is not supported by any variant of SQL that I am aware of.



          i.e.



          Select column1, column2 From 'Tablename%'


          is not valid SQL. You must say...



          Select column1, column2 From Tablename


          where Tablename exists as a table in your database






          share|improve this answer















          SQL Injection concerns aside this is not valid SQL. You are trying to make your table name 1) a string and 2) wild carded. This is not supported by any variant of SQL that I am aware of.



          i.e.



          Select column1, column2 From 'Tablename%'


          is not valid SQL. You must say...



          Select column1, column2 From Tablename


          where Tablename exists as a table in your database







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 11:55

























          answered Nov 22 '18 at 9:55









          CiaránCiarán

          2,65211015




          2,65211015

























              0














              What is it that makes you have several distinct tables in your database that you should be able to do that same SELECT from ?



              In principle, if you have that situation, then there must be some information element that distinguishes those tables from one another, and the intent of the relational model is for such tables to be combined into one, with the distinguishing element included as an additional attribute (/column).






              share|improve this answer




























                0














                What is it that makes you have several distinct tables in your database that you should be able to do that same SELECT from ?



                In principle, if you have that situation, then there must be some information element that distinguishes those tables from one another, and the intent of the relational model is for such tables to be combined into one, with the distinguishing element included as an additional attribute (/column).






                share|improve this answer


























                  0












                  0








                  0







                  What is it that makes you have several distinct tables in your database that you should be able to do that same SELECT from ?



                  In principle, if you have that situation, then there must be some information element that distinguishes those tables from one another, and the intent of the relational model is for such tables to be combined into one, with the distinguishing element included as an additional attribute (/column).






                  share|improve this answer













                  What is it that makes you have several distinct tables in your database that you should be able to do that same SELECT from ?



                  In principle, if you have that situation, then there must be some information element that distinguishes those tables from one another, and the intent of the relational model is for such tables to be combined into one, with the distinguishing element included as an additional attribute (/column).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 14:28









                  Erwin SmoutErwin Smout

                  14.9k42148




                  14.9k42148






























                      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%2f53405383%2fhow-to-select-certain-table-in-my-database%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

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin