Help Copying single row to same table 2 posts

OP Sat Jul 28, 2018 7:08 am
User avatar
Little
Inner Family Member
  • Gender: Female
  • Posts: 340
  • Joined: Mar, 2018
  • Advertisements: 6
  • Karma: 33
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.


Code
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;                       

                    }               


Code
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:.....
Wed Jun 05, 2019 5:33 pm
User avatar
  • Posts: 37
  • Joined: May, 2019
  • Karma: 0
It looks dope to me.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT