Concurrency Violation updating a DataSet

G

Guest

Hell

I've this code

Dim cmdNoleggi As New SqlComman
cmdNoleggi.Connection = _con
cmdNoleggi.CommandText = strSQLNolegg

Dim daNoleggi As New SqlDataAdapter(cmdNoleggi
Dim cbNoleggi As New SqlCommandBuilder(daNoleggi

'I do all the modifies to my DataSet, then.....
'....

'Finally

daNoleggi.Update(_ds.GH_Noleggi

At this point I get a Concurrency Violation error. The fact is that no other peple are modifying this data, so why does it give me errors

Thanks for your help
 
W

William Ryan eMVP

CommandBuilder's have very limited ability to deal with Concurrency and
essentially, if you look at what they generate, you'll see that basically
everything has to match. I'd advise doing a debug.WriteLine on the
SelectCommand, Update Command etc for the commandbuilder so you can see what
it's actually generating. Also, just as an FYI, remember that the
CommandBuilder creates the other commands by virtue of the select statement,
so you have to make sure that your key fields for instance are contained in
the select query. Bill Vaughn has a great article on it at
www.betav.com ->Articles- > MSDN , Weaning Developers from the
commandbuilder.

Anyway, if the Adapter the commandbuilder is helping sees a rowstate as
Modified for instance, and then can't find a row to match one the update,
then it will throw a Concurrency Exception assuming that its been modified
even though it hasn't. So I'm guessing that something is happening in
your SELECT statement that may be causing this. I believe it generates a
different exception if the problem is lack of a primary key (something like
Update Command must use Updateable query or something like that) so that's
probably not it.

Like I said though, since the CB uses the SELECT command to generate its
logic, you need to start there (assuming you are positive that nothing else
is modiying the data) and then verify the update/insert/delete commands it's
using.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Andrea Grandi said:
Hello

I've this code:

Dim cmdNoleggi As New SqlCommand
cmdNoleggi.Connection = _conn
cmdNoleggi.CommandText = strSQLNoleggi

Dim daNoleggi As New SqlDataAdapter(cmdNoleggi)
Dim cbNoleggi As New SqlCommandBuilder(daNoleggi)

'I do all the modifies to my DataSet, then......
'.....

'Finally:

daNoleggi.Update(_ds.GH_Noleggi)

At this point I get a Concurrency Violation error. The fact is that no
other peple are modifying this data, so why does it give me errors?
 
G

Guest

? danoleggi.SelectCommand.CommandText

"SELECT IdNoleggio, IdASL, IdProvincia, NomePaziente, CognomePaziente, IsClosed, IdAutistaConsegna, IdAutistaRitiro, IsRicConsegnaTelefonica, IsRicConsegnaFax, DataConsegnaRichiesta, OraConsegnaRichiesta, DataConsegnaEffettiva, IsRicRitiroTelefonica, IsRicRitiroFax, DataRitiroRichiesta, OraRitiroRichiesta, DataRitiroEffettiva, NumeroBollaConsegna, NumeroBollaRitiro, NoteConsegna, NoteRitiro, DataFineNoleggio, IdReparto FROM GH_Noleggi"


? danoleggi.UpdateCommand.CommandText

Referenced object 'UpdateCommand' has a value of 'Nothing'.

How is it possible that UpdateCommand is nothing?
Could this be the problem?
 
W

William Ryan eMVP

Let me take a look at the original code, but having no update command can
defintiely do it . The only thing though is that it should bark at you if
you call update an there's no command, even with a commandbuilder . This
seems opposite of what I'd expect b/c if you are getting a concurrency
violation, it shouldhave a command to determine this. Unless not having an
update command returns this exception but that wouldn't make any sense. I
don't use CB's much, but let me look into it.

Cheers,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Andrea Grandi said:
? danoleggi.SelectCommand.CommandText

"SELECT IdNoleggio, IdASL, IdProvincia, NomePaziente, CognomePaziente,
IsClosed, IdAutistaConsegna, IdAutistaRitiro, IsRicConsegnaTelefonica,
IsRicConsegnaFax, DataConsegnaRichiesta, OraConsegnaRichiesta,
DataConsegnaEffettiva, IsRicRitiroTelefonica, IsRicRitiroFax,
DataRitiroRichiesta, OraRitiroRichiesta, DataRitiroEffettiva,
NumeroBollaConsegna, NumeroBollaRitiro, NoteConsegna, NoteRitiro,
DataFineNoleggio, IdReparto FROM GH_Noleggi"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top