Solved

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

Posted on 2007-11-15
8
7,469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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