Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:48:10+00:00 2026-06-06T14:48:10+00:00

I need to write q query where I check if the table exists, and

  • 0

I need to write q query where I check if the table exists, and if it does I need to insert value in there. I’m always getting compile errors cause my syntax is wrong. Cab anyone please point out to me the proper code?Appreciate it

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
        createDataBase();
        createDataTable();
    }

    private void createDataBase()
    {
       SQLiteDataAdapter  dataBase = new SQLiteDataAdapter();
    }


    private SQLiteConnection getConnection() 
    { 
        return new SQLiteConnection("Data Source=file1.db"); 
    }


    private void ExecuteQuery(string txtQuery)
    {            
     using (SQLiteConnection sqlcon =  getConnection())
     {
            using (SQLiteCommand sqlcmd = sqlcon.CreateCommand())
            {
                sqlcmd.CommandText = txtQuery;
                sqlcon.Open();
                sqlcmd.ExecuteNonQuery();
            }
        }
    }


    private void createDataTable()
    {
        //ExecuteQuery("DROP TABLE IF EXISTS 'RECORDS'");
        //ExecuteQuery("CREATE TABLE RECORDS ( ID varchar(255))");
        //ExecuteQuery("CREATE TABLE (IF NOT EXISTS) 'RECORDS'");
        //("IF (EXISTS (SELECT ID FROM sqlite_master WHERE NAME = 'RECORDS'))");
    }


    private void button1_Click(object sender, EventArgs e)
    {
          AddValue(textBox1.Text);  
        ////ExecuteQuery("IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA <> NULL AND TABLE_NAME = 'RECORDS')) BEGIN INSERT INTO RECORDS (ID) VALUES ('" + textBox1.Text + "')");    
    }


    private void AddValue(string value)
    {
      ExecuteQuery("INSERT INTO RECORDS (ID) VALUES ('" + value + "')");
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:48:11+00:00Added an answer on June 6, 2026 at 2:48 pm

    This is an example

      SQLiteCommand cmd = new SQLiteCommand();
      cmd.Connection = con;
      cmd.Connection.Open();
      cmd.CommandText = "SELECT name FROM sqlite_master WHERE name='MAIN'";
      SQLiteDataReader rdr = cmd.ExecuteReader();
      if (rdr.HasRows)
      {
            cmd.CommandText = "DROP TABLE 'MAIN'";
            cmd.ExecuteNonQuery();
      }
    

    but this is directly from the SQLite site

      SQLiteCommand cmd = new SQLiteCommand();
      cmd.Connection = con;
      cmd.CommandText = "DROP TABLE IF EXIST 'MAIN'";
      cmd.Connection.Open();
      cmd.ExecuteNonQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a query that will go through a table, find duplicate
I need to write the following query so the att field is always a
I have a table of products, and I need to write an SQL query
I'm trying to write a query that will check today's date against my table
I need to write a query where I need to find the ' character.
I need to write a query that returns all object less that or equal
I need to write a query on SQL server to get the list of
I need to write a SQL query which will get me those rows from
I need to write a WordPress query to accomplish the following - I am
Today I came across the need to write a CAML query that uses WHERE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.