Hi all
I am creating a windows app which interacts with a SQL database so data is contantly being called and written to the database.
I have a maddening problem with this set of code and it is driving me up the wall!
When I run my build and call the function below I get an Object reference not set to an instance of the object error. The line of code that is causing the error I have higlighted below in red. The error does not tell me which object is causing the problem.
Can anyone help me with why this is happening? I have an exact copy of the code inserting data into a different dataset and table (within the same SQL database) and it works fine so I am really bemused as to why this code fails! I have been checking through my books and I have created the XML schema correctly and the dataset is being correctly generated from the schema and called correctly so really at a loss as to why I am getting the error.
Can anyone help?
[/I]
I am creating a windows app which interacts with a SQL database so data is contantly being called and written to the database.
I have a maddening problem with this set of code and it is driving me up the wall!
When I run my build and call the function below I get an Object reference not set to an instance of the object error. The line of code that is causing the error I have higlighted below in red. The error does not tell me which object is causing the problem.
Can anyone help me with why this is happening? I have an exact copy of the code inserting data into a different dataset and table (within the same SQL database) and it works fine so I am really bemused as to why this code fails! I have been checking through my books and I have created the XML schema correctly and the dataset is being correctly generated from the schema and called correctly so really at a loss as to why I am getting the error.
Can anyone help?
VB.NET:
[I]Public Function AddPupilAddress()
objAddress = New MIWSBLPupilBrowserand_Details.MIWSBLPupilDetails(strCompany, strApplication)
'get a new address dataset
objAddressData = objAddress.GetNewAddressDS
'initialize a datarow object from the address dataset
[COLOR=Red]Dim objDataRow As DataRow = objAddressData.Tables("PupilAddressDetails").NewRow[/COLOR]
'Set the values in the datarow
objDataRow.Item("addressID") = Guid.NewGuid()
objDataRow.Item("flatnumber") = AddressForm.txtFlatNumber.Text
objDataRow.Item("flatblock") = AddressForm.txtFlatBlock.Text
objDataRow.Item("housenumber") = AddressForm.txtHouseNumber.Text
objDataRow.Item("buildingname") = AddressForm.txtBuildingName.Text
objDataRow.Item("roadname") = AddressForm.txtRoadNameStreet.Text
objDataRow.Item("towncity") = AddressForm.txtTownCity.Text
objDataRow.Item("county") = AddressForm.txtCounty.Text
objDataRow.Item("country") = AddressForm.cboCountry.SelectedIndex
objDataRow.Item("postcode") = AddressForm.txtPostcode.Text
'Add the Data Row to the Dataset
objData.Tables("PupilAddressDetails").Rows.Add(objDataRow)
'add the pupil to the the database
Try
Call objAddress.AddPupilAddress(objData)
Catch ExceptionErr As Exception
Throw New System.Exception
End Try
'Cleanup
Call AddressForm.ClearAddress()
End Function
Last edited: