BindingNavigator

J

JJ

OK, I have a new form and I'm still a newbie, and am using a dataset
created with the designer based on SQL Server 2005 tables. Have
dragged a field from the Data Sources on to my form, and VS2005
created a Binding Navigator. Now, when the add button is pressed, I
want to update the createby and createDate with current info. Where,
in the code do I do this? In the BindingNavigatorAddNewItem_Click
code? These fields are not on the form. Also, whats the best way to
determine whether this is an add, or simply an edit on the form. If
its an edit I want to update modifiedBy and modifiedDate.

Hope this makes sense and thanks for your help.
 
R

RobinS

Do you have a BindingSource also? If you use a BindingSource,
there are all kinds of events you can capture, like AddingNew,
CurrentItemChanged, etc.

I would set those dates when you are actually just about to
update the database.

For general binding info, check out Linda Liu's post to
microsoft.public.dotnet.general called
"RE: VS2005,VB,BindingNavigator: programmatically moving to record"

Robin S
 
J

JJ

I do have a binding source. I believe most of these were added when I
drag the field name from my data source to the form. Can you give me
an example of updating these fields that are not display on the form?

Thanks Robin
 
R

RobinS

Have you written any code to save your data back
to the database?

When you click on <Save> on the BindingNavigator,
or you move to another record, it writes the changes
to the dataset, but not to the underlying data source.

To commit the changes to the database, you would
perform an Update on the table adapter. I would
add this to the <Save> button code.

myTableAdapter.Update(datasetname.tablename)

I'm going to assume that you have the fields in the
DataSet, but are not displaying them on the screen.
Is that right?

I would try to figure out how to capture the
RowChanging event on that table in that dataset.

In the test case I'm looking at, my binding source
is binding to the Customers table. If I set my
Solution Explorer to <Show All Files> and look
at myDataSet.Designer.vb, I can see the event
for CustomersRowChanging, but I can't figure out
how to add an EventHandler for that to my example.
Grrrr. If you could do that, you could change
the date/time stamp before it writes the data.

You can't tell the diff between an Add and an
Edit, though. I'd probably assign a variable
when they hit the <Add> button, then clear it
in the PositionChanged event on the BindingSource
or when they hit Save.

I'll look at this again in the morning when I am
more bright-eyed, and see if I can write an
example to do what you're talking about.

Unless someone else posts an answer before I do.

Robin S
 
J

JJ

Thanks all

Have you written any code to save your data back
to the database?

When you click on <Save> on the BindingNavigator,
or you move to another record, it writes the changes
to the dataset, but not to the underlying data source.

To commit the changes to the database, you would
perform an Update on the table adapter. I would
add this to the <Save> button code.

myTableAdapter.Update(datasetname.tablename)

I'm going to assume that you have the fields in the
DataSet, but are not displaying them on the screen.
Is that right?

I would try to figure out how to capture the
RowChanging event on that table in that dataset.

In the test case I'm looking at, my binding source
is binding to the Customers table. If I set my
Solution Explorer to <Show All Files> and look
at myDataSet.Designer.vb, I can see the event
for CustomersRowChanging, but I can't figure out
how to add an EventHandler for that to my example.
Grrrr. If you could do that, you could change
the date/time stamp before it writes the data.

You can't tell the diff between an Add and an
Edit, though. I'd probably assign a variable
when they hit the <Add> button, then clear it
in the PositionChanged event on the BindingSource
or when they hit Save.

I'll look at this again in the morning when I am
more bright-eyed, and see if I can write an
example to do what you're talking about.

Unless someone else posts an answer before I do.

Robin S
 
R

RobinS

I don't know how to capture the RowChanging event, but
here's a tacky, but effective way, to do what you're
talking about.

You could wire up a change event on all of the editable
controls on the screen, and when it's triggered, set
the CreateDate and CreateBy info. Then it will be
inherently written to the database when you save the data.

I have a routine that will go through all the controls
on a screen (even the ones inside other controls) and
add an event handler for them. Let me know if you need this.

Robin S.
 
R

RobinS

JJ - are you still watching this thread? I have another
idea that is cleaner - do you want it?

Robin S
 

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