Thread: Drop Table

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Drop Table


    Hi, im using vs2010 with sql compact ce. Please could someone explain why the following happens

    string conString = ConfigurationManager.ConnectionStrings["DataTest1.Properties.Settings.ResultsTableConnectionString"].ConnectionString;


    SqlCeConnection con = new SqlCeConnection(conString);
    con.Open();

    SqlCeCommand cmd = new SqlCeCommand("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'testTABLE'", con);

    int i = 0;
    i = int.Parse(cmd.ExecuteScalar().ToString());


    if (i > 0)
    {
    MessageBox.Show("exists");
    SqlCeCommand drt = new SqlCeCommand("DROP TABLE [testTABLE]", con);
    drt.ExecuteNonQuery();
    }
    else
    {
    MessageBox.Show("doesn't exists");

    }


    Before i run the code, ive created a table called testTABLE with 1 column, its clearly there. Run and click button ounce, msgbox 'it exist', drop table executed. click button again, doesn't exist, as expected. End program. The table is still in the database. Why? Without making any alterations run the code and the same happens again. Any Ideas please.
    regards Robert
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    hi, still playing around with this. Im not looking to see if it exists now just creating the table at design time and trying to drop ar run time.
    string conString = ConfigurationManager.ConnectionStrings["DataTest1.Properties.Settings.ResultsTableConnectionString"].ConnectionString;


    SqlCeConnection con = new SqlCeConnection(conString);
    con.Open();
    SqlCeCommand cmd = new SqlCeCommand("DROP TABLE [testTABLE]", con);
    cmd.ExecuteNonQuery();

    I get no error, but it will not drop the table. I can drop the the table at design time just not in code. Any Ideas?
    regerds robert

IMN logo majestic logo threadwatch logo seochat tools logo