Question

This method, part of a Windows CE / CF / .NET1.1 project:

public void createSettingsTable()
{
    public string filename = "\\my documents\\CCRDB.SDF";
    string conStr = "Data Source = " + filename;
    try
    {
        using (SqlCeConnection con = new SqlCeConnection(conStr)
        {
            con.Open();
            using (SqlCeCommand com =  new SqlCeCommand("create table ccr_settings (setting_id INT IDENTITY NOT NULL PRIMARY KEY,  setting_name varchar(40) not null, setting_value(63) varchar not null)", con))
            {
                    com.ExecuteNonQuery();
            }
            con.Close();
        }
    }
    catch (Exception ex)
    {
        CCR.ExceptionHandler(ex, "createSettingsTable");
    }
}

...is seemingly viewed as something entirely foreign by the compiler. Here are the list of err msgs it causes when I paste it in:

enter image description here

Was it helpful?

Solution

Take public out of the 3rd line and add a paren to the end of your using:

public void createSettingsTable()
{
    string filename = "\\my documents\\CCRDB.SDF"; // <- Here
    string conStr = "Data Source = " + filename;
    try
    {
        using (SqlCeConnection con = new SqlCeConnection(conStr)) // <- Here
        {
            con.Open();
            using (SqlCeCommand com =  new SqlCeCommand("create table ccr_settings (setting_id INT IDENTITY NOT NULL PRIMARY KEY,  setting_name varchar(40) not null, setting_value(63) varchar not null)", con))
            {
                    com.ExecuteNonQuery();
            }
            //con.Close(); // this is not needed
        }
    }
    catch (Exception ex)
    {
        CCR.ExceptionHandler(ex, "createSettingsTable");
    }
}

And you don't need that con.Close call.

OTHER TIPS

You are missing a closing paren at the end of your using statement. Should be this:

using (SqlCeConnection con = new SqlCeConnection(conStr)) {
  //...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top