From: Jacob Nichols via .NET 247 <anonymous@dotnet247.com>
Subject: Update fails with System.NullReferenceException
Newsgroups: microsoft.public.dotnet.datatools
Date: Mon, 07 Mar 2005 11:15:12 -0800
I am looping thru text file records and inserting records into a db via
OLEDBDataAdapters. Each input record can have up to 2 addresses defined,
so i tried to create new rows and add them to the datatable associated with
the database address table, then update the database. The code is below.
If I run it as is it fails with the System.NullReferenceException error.
If I uncomment the update statement in the middle it works just fine. My
understanding was that the Update method would cycle thru all changed
records and apply the appropriate insert/update/delete command but that
doesn't seem to be happening for me... what am i missing???
' Insert Account Address
dtSLXAddress.Clear()
If PrimaryAddress <> "" Then
' primary address id was retrieved earlier
dNewRow = dtSLXAddress.NewRow
dNewRow("ADDRESSID") = strSLXAddressId
dNewRow("ENTITYID") = strSLXAccountId
dNewRow("DESCRIPTION") = "InfoUSA Main"
dNewRow("ADDRESS1") = PrimaryAddress
dNewRow("CITY") = PrimaryCity
dNewRow("STATE") = PrimaryState
dNewRow("POSTALCODE") = PrimaryZip10
dNewRow("COUNTY") = CountyName
dNewRow("ISPRIMARY") = "T"
dNewRow("ISMAILING") = "T"
dNewRow("CREATEDATE") = Now.ToString("yyyy-MM-dd
HH:mm:ss")
dNewRow("CREATEUSER") = "ADMIN"
dNewRow("MODIFYDATE") = Now.ToString("yyyy-MM-dd
HH:mm:ss")
dNewRow("MODIFYUSER") = "ADMIN"
dNewRow("LATITUDE") = Latitude
dNewRow("LONGITUDE") = Longitude
dNewRow("CARRIERRT") = PrimaryCarrierRouteCode
dNewRow("ABIMATCHLEVEL") = MatchLevelCode
dNewRow("ABIDLVPBC") = DeliveryPointBarCode
dtSLXAddress.Rows.Add(dNewRow)
End If
'daSLXAddress.Update(dtSLXAddress)
If SecondaryAddress <> "" Then
dNewRow = dtSLXAddress.NewRow
' get secondary address id
strSLXAddressId = GetSLXId("ADDRESS")
dNewRow("ADDRESSID") = strSLXAddressId
dNewRow("ENTITYID") = strSLXAccountId
dNewRow("DESCRIPTION") = "InfoUSA Secondary"
dNewRow("ADDRESS1") = SecondaryAddress
dNewRow("CITY") = SecondaryCity
dNewRow("STATE") = SecondaryState
dNewRow("POSTALCODE") = SecondaryZip10
dNewRow("ISPRIMARY") = "F"
dNewRow("ISMAILING") = "F"
dNewRow("CREATEDATE") = Now.ToString("yyyy-MM-dd
HH:mm:ss")
dNewRow("CREATEUSER") = "ADMIN"
dNewRow("MODIFYDATE") = Now.ToString("yyyy-MM-dd
HH:mm:ss")
dNewRow("MODIFYUSER") = "ADMIN"
dNewRow("CARRIERRT") = SecondaryCarrierRouteCode
dtSLXAddress.Rows.Add(dNewRow)
End If
daSLXAddress.Update(dtSLXAddress)
--------------------------------
From: Jacob Nichols
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>OgO6C943gEOQqSJ19wvoQg==</Id>
Val Mazur (MVP) - 28 Apr 2005 03:07 GMT
Hi,
How did you open your dtSLXAddress? Was it opened against database first or
not? If DataTable was not opened against a database, then DataAdapter will
not update it.

Signature
Val Mazur
Microsoft MVP
http://xport.mvps.org
> From: Jacob Nichols via .NET 247 <anonymous@dotnet247.com>
> Subject: Update fails with System.NullReferenceException
[quoted text clipped - 68 lines]
> Posted by a user from .NET 247 (http://www.dotnet247.com/)
> <Id>OgO6C943gEOQqSJ19wvoQg==</Id>