Hi,
I'm writing a C# program that interfaces with a SQL Server 2005
database (I use Visual Studio 2005 Professional Edition as compiler).
I have defined the classical ADO.NET SqlDataAdapter, DataSet and
DataTable objects so that, once the database has been loaded with the
SqlDataAdapter Fill method, you work with the data off-line.
I would like to put a control in the Form OnClosing event handler
method: if there are some changes pending, there should be a MessageBox
that asks the user if he wants to save the changes; otherwise (no
changes pending), the Form closes without warnings.
The only way I have thought to do that is the following:
protected override void OnClosing(Syste m.ComponentMode l.CancelEventAr gs
e)
{
Base.OnClosing( e);
DataRow[] adrChangedRows = dtTable.Select( "", "",
DataViewRowStat e.Added |
DataViewRowStat e.ModifiedCurre nt | DataViewRowStat e.Deleted);
if (drChangedRows. Length 0)
{
DialogResult dlgChange = MessageBox.Show ("The database has
changed; do you want to
save the changes?", "Warning",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Warning);
if (dlgChange == DialogResult.Ye s)
daTable.Update( drChangedRows);
else if (dlgChange == DialogResult.No )
dtTable.RejectC hanges(); // probably unuseful, but for clearness
else // if (dlgChange == DialogResult.Ca ncel)
e.Cancel = true;
}
}
Do you think there is a faster (and more elegant) way to do that?
Thank you very much 2 1827
Hi,
There's no better place to prompt the user and cancel the operation than in
the Closing event, IMO.
But you might want to use one of the DataSet.HasChan ges method overloads
instead of dtTable.Select( ...).
Also, you may want to look into control validation events and properties to
prevent attempting to save incomplete or bad data.
--
Dave Sexton
"polocar" <po*****@tin.it wrote in message
news:11******** *************@k 70g2000cwa.goog legroups.com...
Hi,
I'm writing a C# program that interfaces with a SQL Server 2005
database (I use Visual Studio 2005 Professional Edition as compiler).
I have defined the classical ADO.NET SqlDataAdapter, DataSet and
DataTable objects so that, once the database has been loaded with the
SqlDataAdapter Fill method, you work with the data off-line.
I would like to put a control in the Form OnClosing event handler
method: if there are some changes pending, there should be a MessageBox
that asks the user if he wants to save the changes; otherwise (no
changes pending), the Form closes without warnings.
The only way I have thought to do that is the following:
protected override void OnClosing(Syste m.ComponentMode l.CancelEventAr gs
e)
{
Base.OnClosing( e);
DataRow[] adrChangedRows = dtTable.Select( "", "",
DataViewRowStat e.Added |
DataViewRowStat e.ModifiedCurre nt | DataViewRowStat e.Deleted);
if (drChangedRows. Length 0)
{
DialogResult dlgChange = MessageBox.Show ("The database has
changed; do you want to
save the changes?", "Warning",
MessageBoxButto ns.YesNoCancel, MessageBoxIcon. Warning);
if (dlgChange == DialogResult.Ye s)
daTable.Update( drChangedRows);
else if (dlgChange == DialogResult.No )
dtTable.RejectC hanges(); // probably unuseful, but for clearness
else // if (dlgChange == DialogResult.Ca ncel)
e.Cancel = true;
}
}
Do you think there is a faster (and more elegant) way to do that?
Thank you very much This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Windsor |
last post by:
I hope the following describe what I'm trying to do:
I have created a tool to be used by product analysts when studying different
cell phone designs. Part of the tool is a set of 11 forms on a tab
structure with fields for various features a phone might have; there are
almost 100 of these features to choose from. Rather than a simple check
box, I used a combo box with the a value list of "Y, N, N/A, and ?"; I even
simplified entry by...
|
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 the number of ticks using (ADO)
rst.Open "SELECT COUNT(update_po_ref) AS update_qty FROM dbo.tbl_forecasted
|
by: Patrick |
last post by:
I'm working on a contact management application, and need a hand with one
aspect...
Here's what I want to create:
------------------------------------
A form split into two parts. There is a datagrid on the left side that lists
names and perhaps a couple of other key fields. The user can click on a
record in the datagrid, which should automatically pull up details on that
record in the various text boxes and other controls on the right...
|
by: Neo Geshel |
last post by:
Greetings.
I have a serious problem. I have multiple sets of tables, several of
which are chained more than two tables deep. That is, I have a parent, a
child, and a great-grandchild table.
Currently, I am allowing the parent to be edited by itself. In order to
get to a child table, a user needs to select a specific parent table ID.
I have set this up using panels, and putting a drop-down list in the
first panel, with its contents...
|
by: Jonathan Upright |
last post by:
Greetings to anyone who can help:
I'm using WebMatrix to make ASP.NET pages, and I chose the "Editable
DataGrid" at the project selector screen. As you may know, it defaults
to the Microsoft SQL database "pubs". I've followed the instructions in
the comments and also changed everything pertaining to SQL over to
OLEDB. (i.e. Changed SqlDbType. to OleDbType.) I also changed the
datafield names and variable names accordingly. The page...
| |
by: vsiat |
last post by:
I am trying to create a treeview out of a database table
with the typical structure ID, NAME, PARENTID, TYPE,
EXTRA_INFO, where is linked to the .
What I want to achieve is create a tree made of custom,
extended nodes, which include all the extra information
contained in the table and not just typical TreeNode
objects.
To do that, I first created a structure with all the extra
|
by: colmkav |
last post by:
Hi, could someone tell me how I can check whether a database is open
by name
eg something like db("mydbname")
|
by: =?Utf-8?B?SHVzYW0=?= |
last post by:
Hi EveryBody:
I made web site using asp.net 2.0 Vb.Net. The project depends on database in
the local machine. The web site has
• Create User Wizard and
• Login form
When the user is created the username and password saved in the database.
And the code is as follows:
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e
|
by: bloukopkoggelmander |
last post by:
Hi All wonderfull brains!
Right I have two questions after my last very successfull thread. I have tried looking these up on the net, but no luck.
Scenario 1 is : I have a bound form with bound controls. For one of the controls I look up the values from a table, but the values I then sleect from this combo box, is concatednated, ie. Lastname,Firstname,Employee number. Now what I want is that once the user has selected a concatenated name...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |