您好,
没有完整的demo,不过下面的代码可以实现,增,改和查。删除的话只要删除dt里对应的数据即可。
同步回数据库的逻辑需要您自己实现。
- string conStr = "Provider=Microsoft.JET.OLEDB.4.0;data source= " + Application.StartupPath + "\\Patients2000.mdb";
- string sqlStr = "SELECT * FROM Patients";
- System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(conStr);
- DataSet ds = new DataSet();
- System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqlStr, conn);
- fpSpread1.ActiveSheet.DataAutoSizeColumns = false;
- fpSpread1.ActiveSheet.DataMember = "Patients";
- da.Fill(ds);
- fpSpread1.ActiveSheet.DataSource = ds;
- DialogResult dlg;
- dlg = MessageBox.Show("Do you want to add a row to the data source?", "AddRowToDataSource", MessageBoxButtons.YesNo);
- if (dlg == DialogResult.Yes)
- {
- fpSpread1.ActiveSheet.AddUnboundRows(1, 2);
- fpSpread1.ActiveSheet.SetValue(2, 0, "Daly");
- fpSpread1.ActiveSheet.SetValue(2, 1, "John");
- fpSpread1.ActiveSheet.SetValue(2, 2, "111390");
- fpSpread1.ActiveSheet.SetValue(2, 3, "12 Courtney Place");
- fpSpread1.ActiveSheet.AddRowToDataSource(2, true);
- }
复制代码 |