Solved

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

Posted on 2007-11-15
8
7,461 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
Comment Utility
****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
Comment Utility
try have a look at this article
http://www.homeandlearn.co.uk/NET/nets12p9.html

vbturbo
0
 
LVL 18

Expert Comment

by:vbturbo
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

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

Expert Comment

by:vbturbo
Comment Utility
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
Comment Utility
I can't run it
is under net 2003?
thank you
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

12 Experts available now in Live!

Get 1:1 Help Now