Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 189813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:12:14+00:00 2026-05-11T16:12:14+00:00

I am trying to pass an array of values into an array of a

  • 0

I am trying to pass an array of values into an array of a table object so that I can write them to the database.

My database looks like this ->

tblCaseNotes

CaseNoteID | PersonId | etc, etc

tblCaseNotesContactType

rowguid | CaseNoteID | ContactTypeID

tblMaintItems

itemID | CategoryID

The itemID from the Maint table is what is being written to the tblCaseNotesContactType along with the current CaseNoteID. There can be multiple ContactTypes per CaseNote.

What I have so far is an array of the Values for the CheckListBox ContactType created in my btnNew_Click Event:

// Contact Type check list box
int cTypeCount = chkContactType.CheckedItems.Count;
int [] contactTypes = new int[cTypeCount];

// reusable generic counter for looping thru the check lists
int cMaintCounter = 0;

foreach (int checkedItem in chkContactType.CheckedIndices)
{
    contactTypes[cMaintCounter] = (int)chkContactType.GetItemValue(checkedItem);
    cMaintCounter++;
}
CurrentCaseNote.AddCNote(Program._CurrentPerson.PersonID, Convert.ToDecimal(tbxTimeSpentUnits.Text), chkIsCaseLog.Checked, Convert.ToDateTime(datContactDate.Text), memContactDetails.Text, contactTypes);

Which I then pass to my CurrentCaseNote object AddCNote method.

public static void AddCNote(int personID, decimal tsUnits, bool isCaseLog, DateTime cDate, string cDetails, int[] cTypes)
{
    var caseNoteToAdd = new tblCaseNote
                            {
                                CaseNoteID = Guid.NewGuid(),
                                PersonID = personID,
                                TimeSpentUnits =tsUnits,
                                IsCaseLog =isCaseLog,
                                ContactDate =cDate,
                                ContactDetails =cDetails,
                                InsertDate = DateTime.Now,
                                InsertUser = Environment.UserName
                            };

    tblCaseNotesContactType[] cTypeToAdd = new tblCaseNotesContactType[cTypes.Length];
    cTypeToAdd[0].CaseNoteID = caseNoteToAdd.CaseNoteID;
    cTypeToAdd[0].ContactTypeID =cTypes[0];
    cTypeToAdd[0].rowguid = Guid.NewGuid();

    CaseNoteDAL.addCNote(caseNoteToAdd,cTypeToAdd);

It is then passed to the DAL to be written to the local database:

public static void addCNote(tblCaseNote caseNote, tblCaseNotesContactType[] cType)
{
    foreach (var type in cType)
    {
        caseNote.tblCaseNotesContactTypes.Add(type);               
    }
    dcCaseNotes.tblCaseNotes.InsertOnSubmit(caseNote);

    //dcCaseNotes.tblCaseNotes.InsertOnSubmit(caseNoteToAdd);
    dcCaseNotes.SubmitChanges();
}

It is giving me a NUllReferenceException was unhandled error on this line –>cTypeToAdd[0].CaseNoteID = caseNoteToAdd.CaseNoteID;


Is it because I am only working with the [0]? I just did that to simplify my testing of this. When I step through the code my value array is correct and there is a Guid for caseNoteToAdd.CasNoteID

Can someone give me a few pointers on where I am going wrong here and what might be causing the error? As you can tell from my code I am new to this and I am learning on the fly.

Thanks,

~P

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:12:14+00:00Added an answer on May 11, 2026 at 4:12 pm

    The problem is that you’ve created an array of reference types, but not populated it.

    In other words, after this line:

    tblCaseNotesContactType[] cTypeToAdd = new tblCaseNotesContactType[cTypes.Length];
    

    you’ve got an array of null references – the value of each element is null.

    You then need to write:

    cTypeToAdd[0] = new tblCaseNotesContactType();
    

    (or a similar statement) before you can start changing its properties.

    An alternative would be to use an object initializer and do it in one statement (after creating the array):

    cTypeToAdd[0] = new tblCaseNotesContactType
    {
        CaseNoteID = caseNoteToAdd.CaseNoteID,
        ContactTypeID =cTypes[0],
        rowguid = Guid.NewGuid()
    }:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 272k
  • Answers 272k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer True, Google App Engine is a very cool product, but… May 13, 2026 at 1:56 pm
  • Editorial Team
    Editorial Team added an answer In the console, above the stack trace, it should say… May 13, 2026 at 1:56 pm
  • Editorial Team
    Editorial Team added an answer I posted my solution here: http://djcode.posterous.com/installing-mysql-on-mac-os-x-snow-leopard Thanks for the help! May 13, 2026 at 1:56 pm

Related Questions

Lets say I have an array of javascript objects, and I am trying to
Hopefully this will be the last question I need to ask about this..lol.. I
I have a class that encrypts and decrypts a string. It uses rijndael .
I am trying to pass an array of a simple object to a web

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.