long record insert into Access using c#

Hi, I have a long record i'm trying to add to access using c#

but when I use the table.rows.add using an object it fails at the bottom,

The data in the array lines up with my columns in the datatable, although I'm not 100% confident I'm handling the autoincrement ID in the first field. I'm using "null" bc I'm expecting the database to generate it.

Can you help?

private static DataRow addDR(DataTable prtab, double[] dtAr, int[] CrvID, Int64 sims, double[,] crNs, int rNum)
        {

           
            int ln = dtAr.Length;
            object[] arr = new object[ln+2];
                for (int j = 0; j < ln + 2; j++)
                {
                    if (j == 0)
                    {
                        arr[j] = null;
                    }
                    else if (j == 1)
                    {
                        arr[j] = rNum;
                    }
                    else
                    {
                        arr[j] = crNs[rNum, j - 2];
                    }
                   
                }
            prtab.Rows.Add(arr);  fails here

            return prtab.Rows.Add(arr);
        }
MarkH12518Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
You do NOT fill an autoincrement field yourself, not even with a null value.  Access fills that field for you.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note that you can fill an AutoIncrement field if you must, but it must be unique in the column and as Andy said, it can never be NULL. That said, there is almost never a reason to fill an AutoNumber field - about the only time I could see doing so would be when you need to replicate a table for some reason.
MarkH12518Author Commented:
I just modified this code to fill a datarow by not touching the ID field. Should this generate a returnable datarow? I'm going to have to reboot my computer as it is not allowing me to copy my updated dll over to the folder I need it. Any advice helpful though.


private static DataRow addDR(DataTable prtab, double[] dtAr, int[] CrvID, Int64 sims, double[,] crNs, int rNum)
        {

           
            int ln = dtAr.Length;
            object[] arr = new object[ln+2];
                for (int j = 1; j < ln + 2; j++)
                {
                    if (j == 1)
                    {
                        arr[j] = rNum;
                    }
                    else
                    {
                        arr[j] = crNs[rNum, j - 2];
                    }
                   
                }
            prtab.Rows.Add(arr);

            return prtab.Rows.Add(arr);
        }
AndyAinscowFreelance programmer / ConsultantCommented:
>>Should this generate a returnable datarow?
Yes (providing it doesn't throw an exception = adding failed)
ps.  You are adding the array twice to your table in that code - creating two rows.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkH12518Author Commented:
thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.