private void bnSubmit_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
SqlConnection conekt = new SqlConnection(DB_CONN_STRING);
Content content = new Content(conekt);
try
{
content.Insert(Convert.ToInt32(tbfamilyID.Text), tbfName.Text, tbmName.Text, tblName.Text, tbMaiden.Text, tbDOB.Text, tbSOB.Text, tbCoOB.Text, tbCiOB.Text, tbDOD.Text, tbSOD.Text, tbCoOD.Text, tbCiOD.Text, tbCaOD.Text, tbMiscDetails.Text);
tbfName.Text = "";
tbmName.Text = "";
tblName.Text = "";
tbMaiden.Text = "";
tbDOB.Text = "";
tbSOB.Text = "";
tbCoOB.Text = "";
tbCiOB.Text = "";
tbDOD.Text = "";
tbSOD.Text = "";
tbCoOD.Text = "";
tbCiOD.Text = "";
tbCaOD.Text = "";
tbMiscDetails.Text = "";
} // End try.
catch (SqlException err)
{
lbError.Text = "Sorry, the following error occured: " + err.Message;
} // End catch.
} // End if.
} //---------------------------------------- End private void bnSubmit_Click().
This code is in the .cs file for a C# .aspx file. When trying to submit data to SQL Server 2005 on the bnSubmit_Click event the System.NullReferenceException is generated.
The source error: points to the content.Insert method as seen in the above code. I know this is generated because I'm trying to use a reference variable who's value is Nothing/null. However, there are cases where the data from at least one of the TextBox's is going to be empty and I don't need any data sent to that particular record in the table.
This is the Stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Genealogy.Content.Insert(Int32 familyID, String firstName, String middleName, String lastName, String maidenName, String dateOfBirth, String stateOfBirth, String countyOfBirth, String cityOfBirth, String dateOfDeath, String stateOfDeath, String countyOfDeath, String cityOfDeath, String causeOfDeath, String miscDetails) +1186
Genealogy.AddIndividuals.bnSubmit_Click(Object sender, EventArgs e) in c:\staging\Genealogy\addIndividuals.aspx.cs:94
System.Web.UI.WebControls.Button.onclick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921
Any ideas on how I can make this work?

New Topic/Question
Reply




MultiQuote



|