0

此方法是 Windows CE/CF/.NET1.1 项目的一部分:

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");
    }
}

...似乎被编译器视为完全陌生的东西。以下是我粘贴时它导致的错误消息列表:

在此处输入图像描述

4

2 回答 2

6

从第 3 行中取出public并在您的末尾添加一个括号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");
    }
}

你不需要那个con.Close电话。

于 2013-07-30T23:41:34.833 回答
3

您在using语句末尾缺少一个结束括号。应该是这样的:

using (SqlCeConnection con = new SqlCeConnection(conStr)) {
  //...
}
于 2013-07-30T23:41:33.933 回答