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

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко