Re: Ado.net Concurrency exceptions
- From: "W.G. Ryan - MVP" <WilliamRyan@xxxxxxxxxxxxxxxx>
- Date: Wed, 12 Oct 2005 09:17:00 -0400
Ed - comments inline
"Ed Warren" <eowarren@xxxxxxxxxxxxxxx> wrote in message
news:%23U%23D5uyzFHA.3588@xxxxxxxxxxxxxxxxxxxxxxx
> I'm trying to figure out how to use Ado.net with Visual Studio 2003.
>
> I have a very, very simple setup.
>
> Winforms:
>
> Datagrid1 with a datasource set to datasetTest1
>
> oledbconnection1 connected to an access database with one table
> (appointments)
>
> OleDbDataAdapter1 using OleDbConnection1
>
> DataSetTest1 with one table (appointments) :: generated from
> OleDbDataAdapter1
>
> the application opens and fills the dataset (I can see the values in the
> datagrid.
>
> I edit the one of the values in the datagrid and that appears to work
>
> When I run the code below to post back to the database I get an
> OleDBConcurrency exception thrown (on the update command)
>
> I have spent several hours trying to find out why and/or figure out how to
> troubleshoot this.
>
>
>
> Thanks
>
> Ed Warren.
>
> Try
>
---What do your update, insert and delete commands look like?
Are you using a CommandBuilder, the Data Adapter Configuration Wizard or
did you roll your own? This is going to be where the problem is coming in in
all likelihood. Also, have you isolated it so that you are sure no one else
(or no other program) is making changes that could be affecting this? Also,
just to help isolate things, on the Data Adapter configuration wizard, at
the end, you can specify the concurrency options. I'd change this just to
test it and help isolate the problem. If it 'fixes' the problem, then at
least you know exactly where the issue is (although how you handle
concurrency depends on a lot of factors and it may well be a doubleplusbad
to leave it this way).
The Update command is going to be the issue, so if you would, post the
code - that'll definitely help tracking it down. Also, I know I mentioned it
above, but make sure that you isolate things so that you're sure nothing or
no one else is making changes - if they are, then this is precisely the
behavior you want so there may be nothing to fix.
> OleDbDataAdapter1.Update(DataSetTest1)
>
> DataSetTest1.AcceptChanges()
-----When Update is called, the adapter loops through your table, row by row
and checks the rowstate. Then it fires the command that corresponds to the
rowstate for each row if you have it - otherwise you'll throw an exception.
After it calls that command, it calls AcceptChanges on each row, row by row
so this is unnecessary and while it may seem nitpicky to mention this - it
can be confusing to new developers and can potential cause behavior you
weren't expecting. For isntnace, if you called AcceptChanges immediately
before calling Update, then you'd never send the changes back to the
database/
>
> MessageBox.Show("The update was successful!")
>
> Catch ex As Exception
>
> MessageBox.Show("Update Failed", ex.GetType().ToString())
>
> End Try
>
>
.
- Follow-Ups:
- Re: Ado.net Concurrency exceptions
- From: Ed Warren
- Re: Ado.net Concurrency exceptions
- Prev by Date: Re: Equivalent of the .MoveFirst etc. in a DataSet
- Next by Date: Re: Access session variables across asp and aspnet
- Previous by thread: Re: How to trap a Primary Key Constraint Violation
- Next by thread: Re: Ado.net Concurrency exceptions
- Index(es):
Relevant Pages
|