Pullayniece
September 6th, 2008, 11:26 PM
hello everyone,
in the following code, I am trying to call a sub routine which adds information to a row in a database by passing the values from a class function/Structure.
However, when I get passed assigning the two ID columns for the pm K and Foreign K the system reads that I do not have an instance set to an object on.
I have provided example coded below:
Private Sub btnNewFamilySubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewFamilySubmit.Click
Call ValidateEmptybox()
CreateFamily = New Family.FamilyInformation 'Class Declaration.
ValidCreateFamily = New Family.FamilyDetails 'Public Structure declaration.
'Assign the values to the structure FamilyDetails in the Family NameSpace.
CreateFamily.FamilyName = txtFamilyName.Text.ToString
CreateFamily.HomeAddress = txtFamilyStreetAddress.Text.ToString
CreateFamily.HomeCity = txtFamilyCity.Text.ToString
CreateFamily.HomeState = cbFamilyHomeState.Text.ToString
CreateFamily.PostalCode = txtFamilyPostalCode.Text.ToString
CreateFamily.HomePhone = txtFamilyHomePhone.Text.ToString
'Assign the function in the Family NameSpace to the FamilyInformation Class.
ValidCreateFamily = CreateFamily.ValidFamilyInformation
'Pass the Values back from the Family NameSpace function
'after validation and send them to SubmitValidFamily to submit
'the information to the database.
Call SubmitValidFamily(ValidCreateFamily)
End Sub
Private Sub SubmitValidFamily(ByVal ValidFamilyDetail As Family.FamilyDetails)
'Create a New instance of a row in the tblFamily of dsNewFamily DataSet
'Create a new instance of the FamilyDetails Structure in the Family NameSpace.
Dim drCurrentFamily As dsNewFamily.tblFamilyRow
ValidFamilyDetail = New Family.FamilyDetails
Try
'Create a new row and ready it to fill the columns.
drCurrentFamily = DsNewFamily1.tblFamily.NewtblFamilyRow
With drCurrentFamily
'Assign a new GUID
.Fam_ID = Guid.NewGuid
'Check the combobox and select the ID of the Church Selected in the list.
'Then Assign it to the foreign key, Ch_ID.
Dim aIndex As Integer
With cbChurchList
For aIndex = 0 To .Items.Count - 1
drCurrentFamily.Ch_ID = CType(cbChurchList.SelectedValue, Guid)
Exit For
Next
If aIndex >= .Items.Count Then
.SelectedIndex = -1
End If
End With
'Pass the information from the Public Structure FamilyDetails.
'This is were a Null Reference Error appears. Saying an Object Reference
'is not set to an instance of an object.
.Fam_FamilyName = ValidFamilyDetail.FamilyName.ToString
.Fam_HomeAddress = ValidFamilyDetail.HomeAddress.ToString
.Fam_HomeCity = ValidFamilyDetail.HomeCity.ToString
.Fam_HomeState = ValidFamilyDetail.HomeState.ToString
.Fam_HomeZipCode = ValidFamilyDetail.HomePostalCode.ToString
.Fam_HomePhone = ValidFamilyDetail.HomePhone.ToString
.Fam_CreatedOn = CDate((Date.Today.Month & "/" & Date.Today.Day & "/" & Date.Today.Year))
.Fam_FamilyStatus = CInt("1")
End With
DsNewFamily1.tblFamily.Fam_IDColumn.AllowDBNull = True
DsNewFamily1.tblFamily.AddtblFamilyRow(drCurrentFamily)
Catch ex As System.ArgumentException
DsNewFamily1.tblFamily(mintCurrent).CancelEdit()
Catch ex As System.Data.ConstraintException
MessageBox.Show("ID must be unique. Addition cancelled", _
"Error", MessageBoxButtons.OK)
Catch ex As Exception
MsgBox("Can't load Submit Information: Internal System Error." & vbCrLf & ex.Message)
End Try
End Sub
in the following code, I am trying to call a sub routine which adds information to a row in a database by passing the values from a class function/Structure.
However, when I get passed assigning the two ID columns for the pm K and Foreign K the system reads that I do not have an instance set to an object on.
I have provided example coded below:
Private Sub btnNewFamilySubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewFamilySubmit.Click
Call ValidateEmptybox()
CreateFamily = New Family.FamilyInformation 'Class Declaration.
ValidCreateFamily = New Family.FamilyDetails 'Public Structure declaration.
'Assign the values to the structure FamilyDetails in the Family NameSpace.
CreateFamily.FamilyName = txtFamilyName.Text.ToString
CreateFamily.HomeAddress = txtFamilyStreetAddress.Text.ToString
CreateFamily.HomeCity = txtFamilyCity.Text.ToString
CreateFamily.HomeState = cbFamilyHomeState.Text.ToString
CreateFamily.PostalCode = txtFamilyPostalCode.Text.ToString
CreateFamily.HomePhone = txtFamilyHomePhone.Text.ToString
'Assign the function in the Family NameSpace to the FamilyInformation Class.
ValidCreateFamily = CreateFamily.ValidFamilyInformation
'Pass the Values back from the Family NameSpace function
'after validation and send them to SubmitValidFamily to submit
'the information to the database.
Call SubmitValidFamily(ValidCreateFamily)
End Sub
Private Sub SubmitValidFamily(ByVal ValidFamilyDetail As Family.FamilyDetails)
'Create a New instance of a row in the tblFamily of dsNewFamily DataSet
'Create a new instance of the FamilyDetails Structure in the Family NameSpace.
Dim drCurrentFamily As dsNewFamily.tblFamilyRow
ValidFamilyDetail = New Family.FamilyDetails
Try
'Create a new row and ready it to fill the columns.
drCurrentFamily = DsNewFamily1.tblFamily.NewtblFamilyRow
With drCurrentFamily
'Assign a new GUID
.Fam_ID = Guid.NewGuid
'Check the combobox and select the ID of the Church Selected in the list.
'Then Assign it to the foreign key, Ch_ID.
Dim aIndex As Integer
With cbChurchList
For aIndex = 0 To .Items.Count - 1
drCurrentFamily.Ch_ID = CType(cbChurchList.SelectedValue, Guid)
Exit For
Next
If aIndex >= .Items.Count Then
.SelectedIndex = -1
End If
End With
'Pass the information from the Public Structure FamilyDetails.
'This is were a Null Reference Error appears. Saying an Object Reference
'is not set to an instance of an object.
.Fam_FamilyName = ValidFamilyDetail.FamilyName.ToString
.Fam_HomeAddress = ValidFamilyDetail.HomeAddress.ToString
.Fam_HomeCity = ValidFamilyDetail.HomeCity.ToString
.Fam_HomeState = ValidFamilyDetail.HomeState.ToString
.Fam_HomeZipCode = ValidFamilyDetail.HomePostalCode.ToString
.Fam_HomePhone = ValidFamilyDetail.HomePhone.ToString
.Fam_CreatedOn = CDate((Date.Today.Month & "/" & Date.Today.Day & "/" & Date.Today.Year))
.Fam_FamilyStatus = CInt("1")
End With
DsNewFamily1.tblFamily.Fam_IDColumn.AllowDBNull = True
DsNewFamily1.tblFamily.AddtblFamilyRow(drCurrentFamily)
Catch ex As System.ArgumentException
DsNewFamily1.tblFamily(mintCurrent).CancelEdit()
Catch ex As System.Data.ConstraintException
MessageBox.Show("ID must be unique. Addition cancelled", _
"Error", MessageBoxButtons.OK)
Catch ex As Exception
MsgBox("Can't load Submit Information: Internal System Error." & vbCrLf & ex.Message)
End Try
End Sub