Posted 6 years ago
·
Author
Hi guys. I'm trying to copy a single row as a new entry in the same table and make changes to a few cells, including a new Key. Can someone please help.
foreach (DataGridViewColumn Column in dataGridView1.Columns)
{
DataTable dtable = new WorkOrdersDataTable();
//dtable.Columns.Add(new DataColumn("Column 1"));
//dtable.Columns.Add(new DataColumn("Column 2"));
DataRow dr = dtable.NewRow();
DataGridViewRow dgvR = (DataGridViewRow)dataGridView1.CurrentRow.Clone();
if (dr!=null)
{
dataGridView1.DataSource = dtable;
DataTable dataTable = (DataTable)dataGridView1.DataSource;
DataRow drToAdd = dataTable.Rows.Add();
drToAdd["Status"] = "New";
drToAdd["ReportedBy"] = "System: Recurring";
drToAdd["ReportDate"] = dtRecurrent;
drToAdd["WorkOrderNumber"] = Guid.NewGuid();
//dataTable.Rows.Add(drToAdd);
dataTable.AcceptChanges();
dataGridView1.DataSource = workOrdersBindingSource;
}
System.ArgumentExceptionHResult=0x80070057Message=Unable to cast object of type 'System.Guid' to type 'System.IConvertible'.Couldn't store <ec184bf8-ee98-40e2-b18c-644132d7bf25> in WorkOrderNumber Column. Expected type is Int32.Source=System.DataStackTrace:at System.Data.DataColumn.set_Item(Int32 record, Object value)at System.Data.DataRow.set_Item(DataColumn column, Object value)at System.Data.DataRow.set_Item(String columnName, Object value)at SerenityMaintenanceManagementSoftware.Form1.form1_Load(Object sender, EventArgs e) in C:.....