Help Copying single row to same table

Soli
by Soli · 2 posts
5 years ago in .Net (C#, VB, etc)
Posted 5 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.


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:.....
Posted 5 years ago
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