我在这里做错了什么?我正在尝试显示来自远程数据库的数据并插入、编辑和删除数据。我要连接的数据库是一个遥控器,我成功地连接并查看了信息,但是当我插入语法来编辑数据时,我得到一个错误(见帖子底部)。我正在使用 Devexpress 调度程序控制器来查看约会以及编辑它们。
这是整个代码。
public partial class MainWindow : Window
{
CarsDBDataSet dataSet;
public MainWindow()
{
InitializeComponent();
intSchedular();
}
private void intSchedular()
{
schudlerControl1.Storage.AppointmentStorage.Mappings.AllDay = "AllDay";
schudlerControl1.Storage.AppointmentStorage.Mappings.Description = "Description";
schudlerControl1.Storage.AppointmentStorage.Mappings.End = "EndTime";
schudlerControl1.Storage.AppointmentStorage.Mappings.Label = "Label";
schudlerControl1.Storage.AppointmentStorage.Mappings.Start = "StartTime";
schudlerControl1.Storage.AppointmentStorage.Mappings.Location = "Location";
schudlerControl1.Storage.AppointmentStorage.Mappings.ReminderInfo = "RemindderInfo";
schudlerControl1.Storage.AppointmentStorage.Mappings.Subject = "Subject";
schudlerControl1.Storage.AppointmentStorage.Mappings.Status = "Status";
schudlerControl1.Storage.AppointmentStorage.Mappings.Type = "EventType";
schudlerControl1.Storage.AppointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo";
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection()
{
ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source= \\UNDERFOOT-PC\CalUnderFootDB\CarsDB.mdb"
};
con.Open();
OleDbCommand createCommand = new OleDbCommand("select * from CarScheduling", con);
createCommand.ExecuteNonQuery();
OleDbDataAdapter adapter = new OleDbDataAdapter(createCommand);
CarsDBDataSet dataSet = new CarsDBDataSet();
// Bind the scheduler storage to appointment data.
schudlerControl1.Storage.AppointmentStorage.DataSource = dataSet.CarScheduling;
// Load data into the 'CarsDBDataSet.CarScheduling' table.
adapter.Fill(dataSet.CarScheduling);
schudlerControl1.Storage.AppointmentsInserted +=
new PersistentObjectsEventHandler(Storage_AppointmentsModified);
schudlerControl1.Storage.AppointmentsChanged +=
new PersistentObjectsEventHandler(Storage_AppointmentsModified);
schudlerControl1.Storage.AppointmentsDeleted +=
new PersistentObjectsEventHandler(Storage_AppointmentsModified);
adapter.Adapter.RowUpdated +=
new System.Data.OleDb.OleDbRowUpdatedEventHandler(adapter_RowUpdated);
}
void Storage_AppointmentsModified(object sender, PersistentObjectsEventArgs e)
{
adapter.Adapter.Update(dataSet);
this.dataSet.AcceptChanges();
}
private void adapter_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e)
{
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
{
int id = 0;
using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", adapter.Connection))
{
id = (int)cmd.ExecuteScalar();
}
e.Row["ID"] = id;
}
}
}
我得到的错误来自“void Storage_AppointmentsModified”中的适配器一词,说“当前上下文中不存在名称‘适配器’”。我知道我必须定义适配器,但是如何定义?我是 C# 新手,所以我对编写 C# 语法并不“流利”。