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
Solved

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

Posted on 2007-11-15
8
7,467 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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