472,805 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

SQL Server Triggers and Defaults not firing on Windows form

I have a datagrid on a windows form with a bindingnavigator. The
tableadapter, bindingsource and dataset are there also.
I can browse and edit data normally.
I had added the "click" event to the "save" button on the navigator's
toolstrip.
I would like to have the data for the datagrid's table(or tables if it
is a joined recordset) to be updated to the SQL Server table that is
being displayed in the grid.
I used the following code...
private void saveToolStripButton_Click(object sender, EventArgs

e)
{
try
{
this.Validate();
this.partyBindingSource.EndEdit();
this.partyTableAdapter.Update(this.storeDataSet.Pa rty);

MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}
}
}

}
I compared my changes to the SQL table and the changes were there, but
the default values and the values on the fields set by an UPDATE
trigger did not show up.
BTW, the triggers and defaults work when editing in Enterprise Manager
or Query Analyser.

Any ideas?
Also, would this be a good place to call the "Fill" method on the table

adapter to refresh the records after the save/update? (assuming the
triggers and default values work, there would be something to see when
the refresh occurs)
TIA

Jan 15 '06 #1
2 1780
Default constraints only apply on Insert statements, not Updates.

What does the trigger look like? Keep in note that triggers are "set" based,
in that they fire once per batch, not per-row. At best, the last row updated
will be affected by the trigger, which is why it appears to work in
Enterprise Manager, since the editor is row based.

<ce*******@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I have a datagrid on a windows form with a bindingnavigator. The
tableadapter, bindingsource and dataset are there also.
I can browse and edit data normally.
I had added the "click" event to the "save" button on the navigator's
toolstrip.
I would like to have the data for the datagrid's table(or tables if it
is a joined recordset) to be updated to the SQL Server table that is
being displayed in the grid.
I used the following code...
private void saveToolStripButton_Click(object sender, EventArgs

e)
{
try
{
this.Validate();
this.partyBindingSource.EndEdit();
this.partyTableAdapter.Update(this.storeDataSet.Pa rty);

MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}
}
}

}
I compared my changes to the SQL table and the changes were there, but
the default values and the values on the fields set by an UPDATE
trigger did not show up.
BTW, the triggers and defaults work when editing in Enterprise Manager
or Query Analyser.

Any ideas?
Also, would this be a good place to call the "Fill" method on the table

adapter to refresh the records after the save/update? (assuming the
triggers and default values work, there would be something to see when
the refresh occurs)
TIA

Jan 15 '06 #2
Thanks Morgan for helping me think things through.

The problem is:

When a DataSet DataTable includes fields from a table with default
values and/or triggers, the cache in memory has <NULL> values stored
upon .fill method.
So when the database table is updated, the defaults are replaced with
NULLS and the UPDATE trigger wont fire if it depends on the field being
in an UPDATE (SQL Server) state.

Once I removed the fields with default values and UPDATE triggers from
the DataTable Schema, everything worked fine.

If one wants to see default data in a datagridview, I'm having trouble
calling a function in the dataset designer to set the column default
value.
I would love to simple put in the properties for the datatable column a
default value of System.DataTime.Now, but it fails with an error.

Any ideas?

TIA

Jan 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt | last post by:
Hello I am running a SP from the SQL Server Agent, the job has one step that looks like this. exec q_spr_inlevextsystem This job fails with the following message Job 'AutoInlev' : Step...
2
by: aaj | last post by:
Hi all I have a continuous bound form and on each record is a tick box. The user ticks the boxes and these boxes define the batch. for future operations before they leave the page I count...
3
by: Mo | last post by:
Hi, I using server side customvalidator in a FormVIew insert form. It triggers and regardless of the fact if args.IsValid is true or false the data get inserted. am I missing something? ...
0
by: cefrancke | last post by:
I have a datagrid on a windows form with a bindingnavigator. The tableadapter, bindingsource and dataset are there also. I can browse and edit data normally. I had added the "click" event to...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
4
by: =?Utf-8?B?QW1yaXQgS29obGk=?= | last post by:
Hello, I have a button that starts up a Thread and runs it in the background. While the Thread is running, all the Ajax controls, including the events fired by the PageRequestManager, stop...
3
by: Andy Baker | last post by:
I have an SQL Server 2005 database that is populated with a customer's data. I want to create a new database, in exactly the same format, so that I can set up a system for a potential new customer...
4
by: abcd | last post by:
here is the code ---------------------------------------------------------------------------------------- <%@ Register Src="~/UserControls/SegsUC.ascx" TagName="Segs" <asp:Panel...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.