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

  • SEARCH
  • Home
  • 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

Related Questions

I am trying to seperate values in an array so i can pass them
I am trying to pass a array that contains keys and values. The keys
I am trying to pass a single array object (that is a nsdictionary of
I am trying to pass array parameter to SQL commnd in C# like below,
I am currently trying to pass an array that I have created in Javascript
I'm trying to pass this associative array to JavaScript: Array ( [0] => Array
I'm trying to pass a byte array from inside my rails app into another
I'm attempting to create a function where I can pass names and values that
I'm trying to insert the visitor's inputs into a database. This works, but -
Am trying to pass an array of values from PHP function to Javascript. Not

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.