Hi All,

I have two datasets, myds.Tables(0) and UmbrellaFromExcelDataSet.CancelTemplate . I've updated the UmbrellaFromExcelDataSet.CancelTemplate using data from myds.Tables(0) and now I want to put that data update into the database that it orignally came from.

The database isn't updating though.

My code is as follows:

        Me.UmbrellaFromExcelDataSet.CancelTemplate.AcceptChanges()

        Dim csvRow As DataRow
        Dim dbRow As DataRow
        Dim csvURNstring As String
        Dim csvURNnumber As String

        If finalVersion = True Then
            For Each csvRow In myds.Tables(0).Rows
                For Each dbRow In UmbrellaFromExcelDataSet.CancelTemplate.Rows
                    csvURNstring = csvRow.Item("URN").ToString
                    csvURNnumber = csvURNstring.Substring(3, 6)
                    If csvURNnumber = dbRow.Item("URN") Then
                        Me.CancelTemplateTableAdapter.Update(dbRow)
                        Exit For
                    End If
                Next
            Next
        End If

Am I missing something?

Thanks in advance for any help offered.

Recommended Answers

All 4 Replies

Have you tried an update on the whole ds?

for example:

CancelTemplateTableAdapter.UpdateCommand = New SQLCommandBuilder(CancelTemplateTableAdapter).GetUpdateCommand
CancelTemplateTableAdapter.Update(CancelTemplate)

Thanks Begginerdev,

With this though I get the following errors:

Value of type 'Umbrella.UmbrellaFromExcelDataSetTableAdapters.CancelTemplateTableAdapter cannot be converted to 'System.Data.SQLClient.SQLDataAdaptor'

and

'UpdateCommand' is not a member of 'Umbrella.UmbrellaFromExcelDataSetTableAdapters.CancelTemplateTableAdapter'

I've tried

Me.CancelTemplateTableAdapter.Update(Me.UmbrellaFromExcelDataSet.CancelTemplate)

But that also does nothing.

Are you using a custom type that is declared by you, or auto generated by a dataset added to the project?

It's from a datasource that I added using 'Add New DataSource' in the 'Data Sources' section of the toolbox.

I changed

Me.UmbrellaFromExcelDataSet.CancelTemplate.AcceptChanges()

to

Me.UmbrellaFromExcelDataSet.CancelTemplate.GetChanges()

and it does something now but throws that exception:
'A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll'
for each record it attempts to update.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.