this.sfDataGrid1.View.Records.CollectionChanged += Records_CollectionChanged;
private void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
var record = e.NewItems[0] as RecordEntry;
var data = record.Data as DataRowView;
var item = data.Row;
conn.Open();
OleDbCommand insertcommand = new OleDbCommand("INSERT INTO Employee (ID,EmployeeName,EmployeeArea,EmployeeDesignation,EmployeeAge) VALUES (@ID,@EmployeeName,@EmployeeArea,@EmployeeDesignation,@EmployeeAge )");
insertcommand.Parameters.AddWithValue("@EmployeeArea", item.ItemArray[1]);
insertcommand.Parameters.AddWithValue("@EmployeeDesignation", item.ItemArray[2]);
insertcommand.Parameters.AddWithValue("@EmployeeAge", item.ItemArray[3]);
insertcommand.Parameters.AddWithValue("@ID", item.ItemArray[4]);
int result = insertcommand.ExecuteNonQuery();
myDataAdapter.InsertCommand = insertcommand;
conn.Close();
}
} |
OleDbCommand command = new OleDbCommand(
"UPDATE Employee SET EmployeeName = @EmployeeName, EmployeeArea = @EmployeeArea, EmployeeDesignation = @EmployeeDesignation, EmployeeAge = @EmployeeAge " +
"WHERE ID = @ID", conn);
// Add the parameters for the UpdateCommand.
command.Parameters.Add("@EmployeeName", OleDbType.WChar, 255, "EmployeeName");
command.Parameters.Add("@EmployeeArea", OleDbType.WChar, 255, "EmployeeArea");
command.Parameters.Add("@EmployeeDesignation", OleDbType.WChar, 255, "EmployeeDesignation");
command.Parameters.Add("@EmployeeAge", OleDbType.Integer, 10, "EmployeeAge");
command.Parameters.Add("@ID", OleDbType.Integer, 10, "ID");
myDataAdapter.UpdateCommand = command;
conn.Close();
this.sfDataGrid1.DataSource = myDataTable;
sfDataGrid1.CurrentCellEndEdit += SfDataGrid1_CurrentCellEndEdit;
private void SfDataGrid1_CurrentCellEndEdit(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellEndEditEventArgs e)
{
if (!sfDataGrid1.IsAddNewRowIndex(sfDataGrid1.CurrentCell.RowIndex))
myDataAdapter.Update(myDataTable);
} |
sfDataGrid1.RecordDeleting += SfDataGrid1_RecordDeleting;
private void SfDataGrid1_RecordDeleting(object sender, Syncfusion.WinForms.DataGrid.Events.RecordDeletingEventArgs e)
{
conn.Open();
OleDbCommand deletecommand = new OleDbCommand("DELETE FROM Employee WHERE ID = @ID");
deletecommand.Connection = conn;
var id = (e.Items[0] as DataRowView).Row.ItemArray[0];
deletecommand.Parameters.AddWithValue("@ID", id);
myDataAdapter.DeleteCommand = deletecommand;
myDataAdapter.DeleteCommand.ExecuteNonQuery();
conn.Close();
} |
this.sfDataGrid1.RowValidating += SfDataGrid1_RowValidating;
private void SfDataGrid1_RowValidating(object sender, Syncfusion.WinForms.DataGrid.Events.RowValidatingEventArgs e)
{
if (!this.sfDataGrid1.IsAddNewRowIndex(e.DataRow.RowIndex))
{
var data = e.DataRow.RowData as DataRowView;
if (data.Row.ItemArray[1].Equals("Jon"))
{
e.IsValid = false;
e.ErrorMessage = "EmployeeName Jon cannot be passed";
}
}
else
{
var data = e.DataRow.RowData as System.Data.DataRow;
if (data.ItemArray[1].Equals("Jon"))
{
e.IsValid = false;
e.ErrorMessage = "EmployeeName Jon cannot be passed";
}
}
} |