Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I currently have a web form that is connected a database. When a user makes an entry and hit the submit form I want to store the values they have entered in each field. I've debugged the code below and can't seem to see where an object reference is not being set to an instance of an object. I've even checked to see the value value is updated with the corresponding user entry.

C#
protected void uxSubmitBtn_Click(object sender, EventArgs e)
{
    var accountTrackerEntrySVC = new AccountTrackerEntrySVC();

    var result = ViewState["AccountEntryID"] == null ?
    accountTrackerEntrySVC.InsertAccountTrackerEntry(//uxAccountNumTxt.Text.Trim(),
    DataConverter.StringToInteger(ViewState["DataCustodianWorkerNum"].ToString()),
    uxDataBeingTransferredDescTxt.Text.Trim(),
    uxPurposeOrFunctionDialInDescTxt.Text.Trim(),
    uxPhysicalLocationTxt.Text.Trim(),
    uxPurposeOrFunctionDialOutDescTxt.Text.Trim(),
    uxApplicationUtilizingModemDescTxt.Text.Trim(),
    uxPasswordChangeFrequencyDescTxt.Text.Trim(),
    uxOtherLayerAuthenticationDescTxt.Text.Trim(),
    uxMachineServerModeConnectionDescTxt.Text.Trim(),
    CommonSVC.GetUserInfoFormattedFromSession(),
    uxTypeOfconnectionDescTxt.Text.Trim()
    ,modemRequirementCB.Checked
    ,ModemConnectionToNetworkDeviceCB.Checked
    ,PasswordProtectedCB.Checked) :
    accountTrackerEntrySVC.UpdateAccountTrackerEntry(DataConverter.StringToInteger(ViewState["AccountEntryID"].ToString()),
    CommonSVC.GetUserInfoFormattedFromSession(),
    uxDataBeingTransferredDescTxt.Text.Trim(),
    uxPurposeOrFunctionDialInDescTxt.Text.Trim(),
    uxPhysicalLocationTxt.Text.Trim(),
    uxPurposeOrFunctionDialOutDescTxt.Text.Trim(),
    uxApplicationUtilizingModemDescTxt.Text.Trim(),
    uxPasswordChangeFrequencyDescTxt.Text.Trim(),
    uxOtherLayerAuthenticationDescTxt.Text.Trim(),
    uxMachineServerModeConnectionDescTxt.Text.Trim(),
    uxTypeOfconnectionDescTxt.Text.Trim(),
    modemRequirementCB.Checked,
    ModemConnectionToNetworkDeviceCB.Checked,
    PasswordProtectedCB.Checked);

    if (result.Successful)
    {
        uxInfoMsg.DisplayMessage(result.Message, InfoMessage.InfoMessageType.Success);
    }
    else
    {

    }
    //Hide progress indicator
    Master.HideProgressIndicator();
}


Perhaps another pair of eyes will see the error I have yet to spot. Still fairly new to c# so I'll do my best to post responses to any questions you may have. Thanks!
Posted
Updated 20-Jul-15 8:49am
v2
Comments
F-ES Sitecore 20-Jul-15 10:58am    
What line throws the error?
Member 11820531 20-Jul-15 11:04am    
Please see my response to the other question. (same question as yours)
Richard MacCutchan 20-Jul-15 10:58am    
Which line does the error occur on? That will tell you which variable has the null reference, and you can backtrack from there to correct it.
Member 11820531 20-Jul-15 11:03am    
I'm unsure because when I've debugged in the past it will highlight the line where the code fails. In this case the entire block of code I've posted is being highlighted. Correction just the first block is being highlighted. The check result code and //Hid progress indicator code is not highlighted.

"I'm unsure because when I've debugged in the past it will highlight the line where the code fails. In this case the entire block of code I've posted is being highlighted."

Which means it's one (or more) of the parameters you are passing to the InsertAccountTrackerEntry method.
Probably, one of your ViewState names is wrong - "Custodian" spelt elsewhere as "Custodain" or similar for example.
"break out" your variables:
C#
object dcwn = ViewState["DataCustodianWorkerNum"];
before the call, and use the debugger to find out which one is null before you call ToString on them and pass them to your method.

When you know which is null, you can look at finding out why.
 
Share this answer
 
It's actually impossible to say which variable is null based on your code.

The best thing you can do is that you place a breakpoint on the var result = ViewState... code block and when the execution stops over there, using mouse go over each object and see what is null. Alternatively you can use the Watch window or quick watch.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900