Re: custom insert for databound datagridview
- From: "Ginny Caughey MVP" <ginny.caughey.online@xxxxxxxxxxxxxx>
- Date: Thu, 24 Apr 2008 14:47:38 -0400
EndEdit is the point at which the grid desides it's time to really update the changes, and I imagine that gets called by the Save button. The logic in the Save button event handler could look at the data adapter and call GetChanges to see what is different, and you could iterate through the changes, but there might be an easier way to go about it. I think the next step might be to step into everything that happens from the time the Save button is clicked and see where you might want to override something with your own logic.
Ginny
"apitman" <apitman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:12520475-7088-48C3-9FCD-1ECCC65B0887@xxxxxxxxxxxxxxxx
Correction. The IsNew and IsEdit is being set in the CurrentChanged and
CurrentItemChanged, but in ways I don't understand. The IsEdit is always set
when moving from one record to the next even if nothing changed.
I think I am getting the hang of this. There are other parameters in the
classes that indicate things.
I just realized another question however....none of these changes actually
gets put into the database until you hit the save button on the navigation
bar (again using the auto generated stuff). So the user might change stuff
and then change it back and this might mean that I don't want to update my
meta data at the binding source point.
Is there a way to get at the actual point where SQL statements are being
executed on the underlying database?
"Ginny Caughey MVP" wrote:
There probably is a way to insert your own change tracking logic, but I
think using Sync Services, which already provides change tracking logic
inside the SQL Compact engine might be easier in the long run. There is a
CTP you can download that handles syncing with a mobile device, but again
the desktop piece is SQL Server so you'd still need to write a custom sync
adapter to use SQL Compact as the desktop server. Here's the link if the CTP
interests you:
http://www.microsoft.com/Downloads/details.aspx?familyid=75FEF59F-1B5E-49BC-A21A-9EF4F34DE6FC&displaylang=en
Since you're talking about DataGridView, I assume you want to track the
changes on the desktop, but the desktop app doesn't have access to the data
on the device. Are you perhaps considering getting the changed data onto the
device in some other fashion? But in any case, the usual sequence of events
for data bound controls like DataGridView is that moving to a new row in the
grid calls EndEdit which in turn calls Update on the bound data adapter.
Brian Noyes wrote a very good book called Data Binding with Windows Forms
2.0 that covers this sort of stuff in detail, some of which I've
unfortunately forgotten, but the main thing I do remember is tha tthe
BindingSource control is the bit that provides the glue between the GUI
control and the underlying data, so look at the event handlers for
BindingSource such as AddingNew, BindingComplete, CurrentChanged,
CurrentItemChanged, PositionChanged, etc., to see which does what you want.
HTH,
Ginny
"apitman" <apitman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E4BA2AFF-EAFD-4F72-952B-686AD0551B41@xxxxxxxxxxxxxxxx
>I already have a solution for doing the sync part.
>
> The question I really need answered is the original one that I posted
> here:
>
> When I have used all of the built in drag and drop tools to build and
> application how do I get notified when an SQL statement gets called so
> that I
> can do something at that point?
>
> To recap:
>
> I created a form. I put a DataGridView on it. I dragged a data source > onto
> the DataGridView. I told it to generate all the templates.
>
> Now when I use the auto generated UI to create a new record or edit a
> record
> or delete a record I can't seem to find anywhere to get notified of > this.
> I
> put break points inside the data source and other places and nothing > ever
> gets called. Everything just happens auto-magically. That is good > because
> I
> wanted it to be auto-magic so I didn't have to write a bunch of code. > It
> is
> bad because I can't find a place to insert my own logic.
>
> So, is there a way to insert my own logic in this case?
>
>
> "Ginny Caughey MVP" wrote:
>
>> Eventually Sync Services for ADO.NET will support syncing to a variety >> of
>> different relational databases, but the current version doesn't >> support
>> your
>> scenario, so at this point you'd be looking at writing your own sync
>> adapter. Here's a sample for syncing with an Oracle database using a
>> custom
>> sync adapter that you might be able to adapt:
>> http://www.syncguru.com/projects/SyncServicesDemoOracle.aspx
>>
>> Ginny
>>
>> "apitman" <apitman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:4590D3AD-DE73-4B9D-848B-FD9DEF034B59@xxxxxxxxxxxxxxxx
>> > Syncing is exactly what I am doing. I am syncing between a PDA SQLCE
>> > database
>> > and a desktop SQLCE database.
>> >
>> > Unfortunately ADO.NET will only sync between something and SQL >> > Server.
>> > It
>> > does not support syncing between a PDA and SQLCE or even SQLCE and
>> > SQLCE
>> > databases.
>> >
>> > I would love to just use something already out there like ADO.NET
>> > syncing.
>> > If you can tell me there is already something out there, I would >> > LOVE
>> > to
>> > hear
>> > about it. I don't want to roll my own solution, I just seem to be >> > stuck
>> > doing
>> > it.
>> >
>> >
>> > "Ginny Caughey MVP" wrote:
>> >
>> >> You might look at the current changed event handler for the binding
>> >> source
>> >> that is bound to the DataGridView. I'm curious what you want to do
>> >> with
>> >> the
>> >> changed data after you know what it is. For example would Sync
>> >> Services
>> >> for
>> >> ADO.NET (which is designed for change tracking and updating) be a
>> >> solution
>> >> for you?
>> >>
>> >> Ginny
>> >>
>> >>
>> >> "apitman" <apitman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> >> news:950A7F41-3D68-405C-9D54-9E051593E9F7@xxxxxxxxxxxxxxxx
>> >> >I don't know if this is the right forum to post this in, but I >> >> >will
>> >> >start
>> >> > here....
>> >> >
>> >> > I am writing a desktop database application. I created a simple >> >> > SQL
>> >> > CE
>> >> > database. I then created a new form and dragged the DataGridView
>> >> > control
>> >> > from
>> >> > the toolbox to the form.
>> >> >
>> >> > I then created a new data source and pointed it to my desktop >> >> > SQLCE
>> >> > database.
>> >> >
>> >> > I then dragged that data source onto the DataGridView.
>> >> >
>> >> > At this point I have a running application that can insert record
>> >> > into
>> >> > the
>> >> > database.
>> >> >
>> >> > Now comes the fun part. The first field is a Guid. I have read >> >> > many
>> >> > things
>> >> > about the pros and cons of using Guids, but in my case I have
>> >> > decided I
>> >> > want
>> >> > to use them as I will be sharing data among several devices
>> >> > eventually.
>> >> >
>> >> > I made the ID column not visible and then, of course, started
>> >> > getting
>> >> > errors
>> >> > when I created a new row because the Guid was null.
>> >> >
>> >> > If fixed this by creating my own class that derived from the
>> >> > DataGridView
>> >> > and override the OnRowValidating. I did this because that is >> >> > where I
>> >> > was
>> >> > getting the error. I then put in custom logic to check and see if
>> >> > the
>> >> > row
>> >> > guid is blank and if it is I create a new guid.
>> >> >
>> >> > This all works. I tell you about it in case there is a better way
>> >> > and
>> >> > it
>> >> > relates to my second question:
>> >> >
>> >> > I now want to keep track of changes in the database. I created a
>> >> > second
>> >> > table in the database that will contain the Guid of the record >> >> > that
>> >> > was
>> >> > added
>> >> > / changed / deleted and the date / time it happened. I will use >> >> > this
>> >> > to
>> >> > track
>> >> > changes.
>> >> >
>> >> > The problem is that I need to have a place somewhere that I do >> >> > the
>> >> > insert
>> >> > /
>> >> > update of this meta data table when something changes in the main
>> >> > table.
>> >> >
>> >> > SQLCE doesn't support triggers, so that won't work. The benefits >> >> > of
>> >> > SQLCE
>> >> > outweight this, however, and I am hoping there is a solution.
>> >> >
>> >> > So the question is in a data bound situation where can I hook >> >> > into
>> >> > when
>> >> > the
>> >> > SQL statements get run? I put break points all over inside my >> >> > data
>> >> > source
>> >> > class that got created and they never get called. I tried places
>> >> > like
>> >> > the
>> >> > Insert method and Update method. I can only assume those >> >> > functions
>> >> > are
>> >> > for
>> >> > if
>> >> > I want to call them in my code, but the data bound stuff doesn't
>> >> > call
>> >> > them.
>> >> >
>> >> > SQLCE also doesn't support multiple statements in a single call >> >> > so I
>> >> > can't
>> >> > just modify the INSERT INTO statement and put another after it.
>> >> >
>> >> > Ideas?
>> >>
>> >> -- >> >>
>> >> Ginny Caughey
>> >> Device Application Development MVP
>> >>
>> >> www.wasteworks.com
>> >> Software for Waste Management
>> >>
>> >>
>> >>
>>
>> -- >>
>> Ginny Caughey
>> Device Application Development MVP
>>
>> www.wasteworks.com
>> Software for Waste Management
>>
>>
>>
--
Ginny Caughey
Device Application Development MVP
www.wasteworks.com
Software for Waste Management
--
Ginny Caughey
Device Application Development MVP
www.wasteworks.com
Software for Waste Management
.
- Follow-Ups:
- Re: custom insert for databound datagridview
- From: apitman
- Re: custom insert for databound datagridview
- References:
- custom insert for databound datagridview
- From: apitman
- Re: custom insert for databound datagridview
- From: Ginny Caughey MVP
- Re: custom insert for databound datagridview
- From: apitman
- Re: custom insert for databound datagridview
- From: Ginny Caughey MVP
- Re: custom insert for databound datagridview
- From: apitman
- Re: custom insert for databound datagridview
- From: Ginny Caughey MVP
- Re: custom insert for databound datagridview
- From: apitman
- custom insert for databound datagridview
- Prev by Date: Re: custom insert for databound datagridview
- Next by Date: Re: custom insert for databound datagridview
- Previous by thread: Re: custom insert for databound datagridview
- Next by thread: Re: custom insert for databound datagridview
- Index(es):