Solved

update requires a valid updatecommand when passed datarow collection with modified rows

Posted on 2007-11-15
8
7,462 Views
Last Modified: 2012-06-22
Hi.
Im simply use the datasheet wizard for create a dataset with my  sql table for edit, delete update information, but the update buton did not work, taking the error message that have in the question title.

the code is this.
**************************************************
Public Sub UpdateDataSource(ByVal ChangedRows As WindowsApplication1.indice)
        Try
            'Sólo es necesario actualizar el origen de datos si hay cambios pendientes.
            If (Not (ChangedRows) Is Nothing) Then
                'Abra la conexión.
                Me.OleDbConnection1.Open()
                'Intente actualizar el origen de datos.
                'OleDbDataAdapter1.Update(ChangedRows)
                OleDbDataAdapter1.Update(ChangedRows)
                Me.OleDbConnection1.Close()

            End If
        Catch updateException As System.Exception
            'Agregar aquí el código de control de errores.
            Throw updateException
        Finally
            'Cerrar la conexión independientemente de si se inició una excepción o no.
            Me.OleDbConnection1.Close()
        End Try

    End Sub
******************************************
please is anybody help me to fix this error
thank you
edo
0
Comment
Question by:edo60
  • 4
  • 3
8 Comments
 

Author Comment

by:edo60
ID: 20292931
****the error code again*****

Public Sub UpdateDataSource(ByVal ChangedRows As WindowsApplication1.indice)
       

        Try
                        If (Not (ChangedRows) Is Nothing) Then
                               Me.OleDbConnection1.Open()
                                             OleDbDataAdapter1.Update(ChangedRows)
                Me.OleDbConnection1.Close()

            End If
        Catch updateException As System.Exception
                        Throw updateException
        Finally
                       Me.OleDbConnection1.Close()
        End Try

    End Sub

0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20292979
try have a look at this article
http://www.homeandlearn.co.uk/NET/nets12p9.html

vbturbo
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20293016
and here from the beginning
http://www.homeandlearn.co.uk/NET/nets12p4.html

gives an easy and quick way of getting comprehension on how to work with the dataset
if you spend 15 min. walking through

vbturbo
0
 
LVL 16

Expert Comment

by:RobertRFreeman
ID: 20293961
Click on your dataadapter on your form (in the components section).  In  the properties window, look at the insertcommand, updatecommand, and deletecommand properties.  These should be populated.  You can also reconfigure this adapter to try and regenerate these.  Make sure "Generate insert,update, and delete commands is enabled.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:edo60
ID: 20320738
come on you guys an example of array update of your projects
regards
edo
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20321314
try have a look here

https://filedb.experts-exchange.com/incoming/ee-stuff/5731-Relations.zip 

type some data in the one of the grids or create/delete a  row(s)

then do the update made to the tables

vbturbo

NB: watch how many times i use the connection open() and close()
0
 

Author Comment

by:edo60
ID: 20323779
I can't run it
is under net 2003?
thank you
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
ID: 20323854
Hi

if you got the database then try put this code in a form (project made in vs2003)

add 2 datagrids and 1 button

Imports System.Data

Public Class Form1

    Dim con As New OleDb.OleDbConnection
    Dim ds As DataSet
    Dim daParent As OleDb.OleDbDataAdapter
    Dim daChild As OleDb.OleDbDataAdapter
    Dim sql As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Test.mdb"
        sql = "SELECT * FROM Parent"
        con.Open()

        daParent = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet("Parent")
        daParent.FillSchema(ds, SchemaType.Mapped, "Parent")
        daParent.Fill(ds, "Parent")

        sql = "SELECT * FROM Child"
        daChild = New OleDb.OleDbDataAdapter(sql, con)
        daChild.FillSchema(ds, SchemaType.Mapped, "Child")
        daChild.Fill(ds, "Child")

        con.Close()

        Parentgrd.DataSource = ds.Tables("Parent")
        Childgrd.DataSource = ds.Tables("Child")

        ds.Tables("Parent").Columns("ID").AutoIncrement = True
        ds.Tables("Parent").Columns("ID").AutoIncrementSeed = -1
        ds.Tables("Parent").Columns("ID").AutoIncrementSeed = +1

        ds.Tables("Child").Columns("ID").AutoIncrement = True

        SetdataRel()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Parentgrd.EndEdit()

        Dim cb As New OleDb.OleDbCommandBuilder(daParent)
        daParent.Update(ds, "Parent")

        'Childgrd.EndEdit()

        Dim cb1 As New OleDb.OleDbCommandBuilder(daChild)
        daChild.Update(ds, "Child")

        MsgBox("Data updated")
    End Sub
    Public Sub SetdataRel()
        ' Add the relation between ParentTable/ChildTable

        ds.Relations.Add(New DataRelation(relationName:="relParChi", parentColumn:=ds.Tables("Parent").Columns("ID"), _
         childColumn:=ds.Tables("Child").Columns("Foreignkey"), _
         createConstraints:=False))

        ' Set the Parent grid
        Parentgrd.DataSource = ds
        Parentgrd.DataMember = "Parent"

        ' Set the Child grid
        Childgrd.DataSource = ds
        Childgrd.DataMember = "Parent.relParChi"

    End Sub

End Class
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I need help embedding an image as HTML in my vb.net application 3 48
Receiving a string from a WebService Push 21 36
Entity Framework 7 31
VS.net 2010 11 22
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now