hello, hope i post in the right forum.
I've a small app to read data from XML and import into SQL 2005.
My idea is use type dataset, first read data from SQL db into datatable1, create another datatable2 read data from xml, merge datatable2 into datatable1, then update datatable1 back to SQL. Bellow is code:
------------------------------------------------------------
Dim ta As New TypedDataSetTableAdapter
Dim dt1 As TypedDatasetDataTable = ta.GetData
Dim filepath As String = "c:\prjinfo.xml"
Dim xmlSchema As String = "c:\prjinfo.xsd"
Dim xds As New DataSet
xds.ReadXmlSchema(xmlSchema)
xds.ReadXml(filepath)
Dim dt2 As DataTable
dt2 = xds.Tables.Item(0).Copy()
If Not dt1 Is Nothing And Not dt2 Is Nothing Then
dt1.Merge(dt2)
End If
Dim dtChanges AsTypedDatasetDataTable= CType(dt1.GetChanges, TypedDatasetDataTable)
If NotdtChangesIs Nothing Then
ta.Update(dtChanges)
End If
----------------------------------------------------------------------
The problem is every time when runing into dt1.merge(dt2), system throwSystem.NullReferenceException: Object reference not set to an instance of an object.
no matter I use or not use new for dt1, dt2 or both, same result. from debugging, i can see data in dt1 and dt2.
anybody help?
Ay