SQLite C# Error: System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: “'Income”"'2019 Community Moderator ElectionIs there a .NET/C# wrapper for SQLite?C# Equivalent of SQL Server DataTypesTable not found with SQL Lite ADO Providersqlite unrecognized tokenUnrecognized Token : “#” C# to SQLITEUnrecognized token near “@” using SQLITE in C#unrecognized token: “4eL2” c# SQLITEUnrecognized token in SQLite statementSqlite 'Unrecognized token: “:” C++SQLite error unrecognized token Unity

What is the likely impact on flights of grounding an entire aircraft series?

Good allowance savings plan?

My story is written in English, but is set in my home country. What language should I use for the dialogue?

Have researches managed to "reverse time" and if so, what does that mean for physics?

What to do when during a meeting client people start to fight (even physically) with each others?

Making a sword in the stone, in a medieval world without magic

Is "history" a male-biased word ("his+story")?

The three point beverage

What is the blue range indicating on this manifold pressure gauge?

When is a batch class instantiated when you schedule it?

Question about partial fractions with irreducible quadratic factors

Am I not good enough for you?

It's a yearly task, alright

Playing ONE triplet (not three)

Time travel short story where dinosaur doesn't taste like chicken

When were linguistics departments first established

What exactly is the purpose of connection links straped between the rocket and the launch pad

Prove that the total distance is minimised (when travelling across the longest path)

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

Replacing Windows 7 security updates with anti-virus?

Unreachable code, but reachable with exception

Plywood subfloor won't screw down in a trailer home

What has been your most complicated TikZ drawing?

Make a transparent 448*448 image



SQLite C# Error: System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: “'Income”"'



2019 Community Moderator ElectionIs there a .NET/C# wrapper for SQLite?C# Equivalent of SQL Server DataTypesTable not found with SQL Lite ADO Providersqlite unrecognized tokenUnrecognized Token : “#” C# to SQLITEUnrecognized token near “@” using SQLITE in C#unrecognized token: “4eL2” c# SQLITEUnrecognized token in SQLite statementSqlite 'Unrecognized token: “:” C++SQLite error unrecognized token Unity










0















Currently, I have a piece of code which displays the Table in DataGridView



using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM Income", con);
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "Info");
IncomeData.DataSource = ds.Tables[0];



However, because I am going to have to reuse the code multiple time. I decided to create a new class allowing me to do so. As shown below:



public void DBLoad(string tableName, DataGridView DGVname)

DBC = new DatabaseConnection();
DBC.getConnection() // connects to .db file

using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);
System.Data.DataSet ds = new System.Data.DataSet();

da.Fill(ds, "Info");
DGVname.DataSource = ds.Tables[0];




But the problem I am having is that the tableName is going to be in the SQL query and I keep running into the problem of needing to remove the quotation marks.



If I do this:



className.DBLoad("Income", IncomeData); 


Then the following error occurs:




System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: "'Income""'




I tried doing:



tableName = tableName.Replace(""", string.Empty);


But I still get the same error. So now I don't know what do to.










share|improve this question
























  • Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

    – Make StackOverflow Good Again
    Mar 6 at 17:46












  • @MakeStackOverflowGoodAgain what do you mean by a tick?

    – Sonny P.
    Mar 6 at 17:50











  • Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

    – Steve
    Mar 6 at 17:52












  • change to $"SELECT * FROM tableName"

    – Matt.G
    Mar 6 at 17:52












  • @Matt.G This works. Thank You.

    – Sonny P.
    Mar 6 at 17:59















0















Currently, I have a piece of code which displays the Table in DataGridView



using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM Income", con);
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "Info");
IncomeData.DataSource = ds.Tables[0];



However, because I am going to have to reuse the code multiple time. I decided to create a new class allowing me to do so. As shown below:



public void DBLoad(string tableName, DataGridView DGVname)

DBC = new DatabaseConnection();
DBC.getConnection() // connects to .db file

using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);
System.Data.DataSet ds = new System.Data.DataSet();

da.Fill(ds, "Info");
DGVname.DataSource = ds.Tables[0];




But the problem I am having is that the tableName is going to be in the SQL query and I keep running into the problem of needing to remove the quotation marks.



If I do this:



className.DBLoad("Income", IncomeData); 


Then the following error occurs:




System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: "'Income""'




I tried doing:



tableName = tableName.Replace(""", string.Empty);


But I still get the same error. So now I don't know what do to.










share|improve this question
























  • Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

    – Make StackOverflow Good Again
    Mar 6 at 17:46












  • @MakeStackOverflowGoodAgain what do you mean by a tick?

    – Sonny P.
    Mar 6 at 17:50











  • Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

    – Steve
    Mar 6 at 17:52












  • change to $"SELECT * FROM tableName"

    – Matt.G
    Mar 6 at 17:52












  • @Matt.G This works. Thank You.

    – Sonny P.
    Mar 6 at 17:59













0












0








0








Currently, I have a piece of code which displays the Table in DataGridView



using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM Income", con);
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "Info");
IncomeData.DataSource = ds.Tables[0];



However, because I am going to have to reuse the code multiple time. I decided to create a new class allowing me to do so. As shown below:



public void DBLoad(string tableName, DataGridView DGVname)

DBC = new DatabaseConnection();
DBC.getConnection() // connects to .db file

using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);
System.Data.DataSet ds = new System.Data.DataSet();

da.Fill(ds, "Info");
DGVname.DataSource = ds.Tables[0];




But the problem I am having is that the tableName is going to be in the SQL query and I keep running into the problem of needing to remove the quotation marks.



If I do this:



className.DBLoad("Income", IncomeData); 


Then the following error occurs:




System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: "'Income""'




I tried doing:



tableName = tableName.Replace(""", string.Empty);


But I still get the same error. So now I don't know what do to.










share|improve this question
















Currently, I have a piece of code which displays the Table in DataGridView



using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM Income", con);
DataSet ds = new System.Data.DataSet();
da.Fill(ds, "Info");
IncomeData.DataSource = ds.Tables[0];



However, because I am going to have to reuse the code multiple time. I decided to create a new class allowing me to do so. As shown below:



public void DBLoad(string tableName, DataGridView DGVname)

DBC = new DatabaseConnection();
DBC.getConnection() // connects to .db file

using (SQLiteConnection con = new SQLiteConnection(DBC.connectionstring))

con.Open();
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);
System.Data.DataSet ds = new System.Data.DataSet();

da.Fill(ds, "Info");
DGVname.DataSource = ds.Tables[0];




But the problem I am having is that the tableName is going to be in the SQL query and I keep running into the problem of needing to remove the quotation marks.



If I do this:



className.DBLoad("Income", IncomeData); 


Then the following error occurs:




System.Data.SQLite.SQLiteException: 'SQL logic error unrecognized token: "'Income""'




I tried doing:



tableName = tableName.Replace(""", string.Empty);


But I still get the same error. So now I don't know what do to.







c# sql sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 18:01









Hadi

21.2k62774




21.2k62774










asked Mar 6 at 17:41









Sonny P.Sonny P.

135




135












  • Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

    – Make StackOverflow Good Again
    Mar 6 at 17:46












  • @MakeStackOverflowGoodAgain what do you mean by a tick?

    – Sonny P.
    Mar 6 at 17:50











  • Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

    – Steve
    Mar 6 at 17:52












  • change to $"SELECT * FROM tableName"

    – Matt.G
    Mar 6 at 17:52












  • @Matt.G This works. Thank You.

    – Sonny P.
    Mar 6 at 17:59

















  • Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

    – Make StackOverflow Good Again
    Mar 6 at 17:46












  • @MakeStackOverflowGoodAgain what do you mean by a tick?

    – Sonny P.
    Mar 6 at 17:50











  • Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

    – Steve
    Mar 6 at 17:52












  • change to $"SELECT * FROM tableName"

    – Matt.G
    Mar 6 at 17:52












  • @Matt.G This works. Thank You.

    – Sonny P.
    Mar 6 at 17:59
















Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

– Make StackOverflow Good Again
Mar 6 at 17:46






Your first snippet doesnt use a tick, so why does the second, particularly in light of the message complaining about 'Income'? This is generally a bad idea anyway

– Make StackOverflow Good Again
Mar 6 at 17:46














@MakeStackOverflowGoodAgain what do you mean by a tick?

– Sonny P.
Mar 6 at 17:50





@MakeStackOverflowGoodAgain what do you mean by a tick?

– Sonny P.
Mar 6 at 17:50













Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

– Steve
Mar 6 at 17:52






Why do you put single quotes around the variable tablename in your generic query? A tablename should not be treated as a string. By the way, be sure that your users cannot type the value for that variable or bad things could happen

– Steve
Mar 6 at 17:52














change to $"SELECT * FROM tableName"

– Matt.G
Mar 6 at 17:52






change to $"SELECT * FROM tableName"

– Matt.G
Mar 6 at 17:52














@Matt.G This works. Thank You.

– Sonny P.
Mar 6 at 17:59





@Matt.G This works. Thank You.

– Sonny P.
Mar 6 at 17:59












1 Answer
1






active

oldest

votes


















1














As far as i know you don't need ticks near the table name .




The tick is : '




i also recommend you use the String.Format method as follows to replace the table name inside the query :



String.Format("Select * FROM 0",tableName);


so this line of code :



SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);


should be like this :



SQLiteDataAdapter da = new SQLiteDataAdapter(String.Format("Select * FROM 0",tableName), con);


References :



SQLite SELECT - Querying data from a single table



String.Format Method






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%2f55029183%2fsqlite-c-sharp-error-system-data-sqlite-sqliteexception-sql-logic-error-unrec%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









    1














    As far as i know you don't need ticks near the table name .




    The tick is : '




    i also recommend you use the String.Format method as follows to replace the table name inside the query :



    String.Format("Select * FROM 0",tableName);


    so this line of code :



    SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);


    should be like this :



    SQLiteDataAdapter da = new SQLiteDataAdapter(String.Format("Select * FROM 0",tableName), con);


    References :



    SQLite SELECT - Querying data from a single table



    String.Format Method






    share|improve this answer





























      1














      As far as i know you don't need ticks near the table name .




      The tick is : '




      i also recommend you use the String.Format method as follows to replace the table name inside the query :



      String.Format("Select * FROM 0",tableName);


      so this line of code :



      SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);


      should be like this :



      SQLiteDataAdapter da = new SQLiteDataAdapter(String.Format("Select * FROM 0",tableName), con);


      References :



      SQLite SELECT - Querying data from a single table



      String.Format Method






      share|improve this answer



























        1












        1








        1







        As far as i know you don't need ticks near the table name .




        The tick is : '




        i also recommend you use the String.Format method as follows to replace the table name inside the query :



        String.Format("Select * FROM 0",tableName);


        so this line of code :



        SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);


        should be like this :



        SQLiteDataAdapter da = new SQLiteDataAdapter(String.Format("Select * FROM 0",tableName), con);


        References :



        SQLite SELECT - Querying data from a single table



        String.Format Method






        share|improve this answer















        As far as i know you don't need ticks near the table name .




        The tick is : '




        i also recommend you use the String.Format method as follows to replace the table name inside the query :



        String.Format("Select * FROM 0",tableName);


        so this line of code :



        SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT * FROM '" + tableName + '"', con);


        should be like this :



        SQLiteDataAdapter da = new SQLiteDataAdapter(String.Format("Select * FROM 0",tableName), con);


        References :



        SQLite SELECT - Querying data from a single table



        String.Format Method







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 6 at 17:58

























        answered Mar 6 at 17:51









        Ahmad.TrAhmad.Tr

        675618




        675618





























            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%2f55029183%2fsqlite-c-sharp-error-system-data-sqlite-sqliteexception-sql-logic-error-unrec%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

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved