此方法是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");
}
}
......似乎被编译器视为完全陌生的东西。以下是粘贴它时导致的错误信息列表:
答案 0 :(得分:6)
将public
从第3行中取出,并将父级添加到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
来电。
答案 1 :(得分:3)
您在using
声明结尾处错过了结束语。应该是这样的:
using (SqlCeConnection con = new SqlCeConnection(conStr)) {
//...
}