473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

determine after using addnew

is there a way to know if the form is edited or not after calling
addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew()

because i got an error after closing the form. because in my form
closing event i have a code to call the EndCurrentEdit to determine if
the dataset has changes or not. here is my code in closing event

Private Sub Students_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit()
Try
If DsStudentCourse1.HasChanges Then
If MessageBox.Show("There are unsave changes in
the Form, Yes to Save, No to Discard and exit?", "Save changes",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes
Then
Save_Record()
Else
Me.BindingContext(DsStudentCourse1,
"Students").CancelCurrentEdit()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

the problem is in the Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit() line of code after calling addnew and
then closing the form without editing the form.

the error generated is "Column 'IDNo' does not allow nulls." because
IDNo is a primary key.

thanks in advance for any help.
Nov 20 '05 #1
3 1827
I don't know of a way to determine its state, but why not call cancel
current edit. you can tell if the dataset has changes or not by using
DataSet.HasChanges(); which returns a bool. If it doesn't go ahead and
cancel the current edit (depending on how you want the app to behave this
should do it for you).
"jaYPee" <hi******@yahoo.com> wrote in message
news:vm********************************@4ax.com...
is there a way to know if the form is edited or not after calling
addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew()

because i got an error after closing the form. because in my form
closing event i have a code to call the EndCurrentEdit to determine if
the dataset has changes or not. here is my code in closing event

Private Sub Students_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit()
Try
If DsStudentCourse1.HasChanges Then
If MessageBox.Show("There are unsave changes in
the Form, Yes to Save, No to Discard and exit?", "Save changes",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes
Then
Save_Record()
Else
Me.BindingContext(DsStudentCourse1,
"Students").CancelCurrentEdit()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

the problem is in the Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit() line of code after calling addnew and
then closing the form without editing the form.

the error generated is "Column 'IDNo' does not allow nulls." because
IDNo is a primary key.

thanks in advance for any help.

Nov 20 '05 #2
thanks for the reply. however DataSet.HasChanges() is only applicable
when the control is datagrid. don't know if i'm wrong or not. but as i
have experience eventhough i edit the textbox in my form and close the
form and call DataSet.HasChanges() is it returns false.
On Wed, 28 Apr 2004 00:28:47 -0400, "William Ryan eMVP"
<do********@comcast.nospam.net> wrote:
I don't know of a way to determine its state, but why not call cancel
current edit. you can tell if the dataset has changes or not by using
DataSet.HasChanges(); which returns a bool. If it doesn't go ahead and
cancel the current edit (depending on how you want the app to behave this
should do it for you).
"jaYPee" <hi******@yahoo.com> wrote in message
news:vm********************************@4ax.com.. .
is there a way to know if the form is edited or not after calling
addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew()

because i got an error after closing the form. because in my form
closing event i have a code to call the EndCurrentEdit to determine if
the dataset has changes or not. here is my code in closing event

Private Sub Students_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit()
Try
If DsStudentCourse1.HasChanges Then
If MessageBox.Show("There are unsave changes in
the Form, Yes to Save, No to Discard and exit?", "Save changes",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes
Then
Save_Record()
Else
Me.BindingContext(DsStudentCourse1,
"Students").CancelCurrentEdit()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

the problem is in the Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit() line of code after calling addnew and
then closing the form without editing the form.

the error generated is "Column 'IDNo' does not allow nulls." because
IDNo is a primary key.

thanks in advance for any help.


Nov 20 '05 #3
Actually, that's not true. HasChanges has nothign to do with a
Datagrid...the datagrid is only incidental in that it's one mechanism to
edit the data. If HasChanges is false, your update isn't going to do
anything. TO prove it, trap the StateChanged event of your connection. Put
a messagebox in it. Then, right after dataadapter.fill the very next line
(test HasChanges, it will be false). Next, create a loop to 1000 or 10000
or whatever suits you. Then, in the loop call daadapter.Update. You'll
notice that your messagebox never shows. That's because the connection
(which is closed at this point) doesn't open any more (while in the loop
calling Update) which proves it's not sending anything to the db. Next
line, Change a value of the datatable. call dataAdapter.Update again, your
messagebox will show this time. It will show twice on fill, once when it
opens, once when it closes.

hasChanges is a property of the dataset not the grid.
jaYPee" <hi******@yahoo.com> wrote in message
news:f1********************************@4ax.com...
thanks for the reply. however DataSet.HasChanges() is only applicable
when the control is datagrid. don't know if i'm wrong or not. but as i
have experience eventhough i edit the textbox in my form and close the
form and call DataSet.HasChanges() is it returns false.
On Wed, 28 Apr 2004 00:28:47 -0400, "William Ryan eMVP"
<do********@comcast.nospam.net> wrote:
I don't know of a way to determine its state, but why not call cancel
current edit. you can tell if the dataset has changes or not by using
DataSet.HasChanges(); which returns a bool. If it doesn't go ahead and
cancel the current edit (depending on how you want the app to behave this
should do it for you).
"jaYPee" <hi******@yahoo.com> wrote in message
news:vm********************************@4ax.com.. .
is there a way to know if the form is edited or not after calling
addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew()

because i got an error after closing the form. because in my form
closing event i have a code to call the EndCurrentEdit to determine if
the dataset has changes or not. here is my code in closing event

Private Sub Students_Closing(ByVal sender As Object, ByVal e
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit()
Try
If DsStudentCourse1.HasChanges Then
If MessageBox.Show("There are unsave changes in
the Form, Yes to Save, No to Discard and exit?", "Save changes",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes
Then
Save_Record()
Else
Me.BindingContext(DsStudentCourse1,
"Students").CancelCurrentEdit()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

the problem is in the Me.BindingContext(DsStudentCourse1,
"Students").EndCurrentEdit() line of code after calling addnew and
then closing the form without editing the form.

the error generated is "Column 'IDNo' does not allow nulls." because
IDNo is a primary key.

thanks in advance for any help.

Nov 20 '05 #4

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

Similar topics

4
by: Phillip J. Allen | last post by:
Hi all, I have a table with an “autonumber” primary key field that also acts as a foreign key in 2 other tables. I would like to programmatically add a new record to the first table and the...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
2
by: guy | last post by:
if i use Generics.AddNew how do I pass an object to the items constructor? I have a set of class all inheriting from a base class, all requiring one parameter on their constructor - the data...
2
by: pillmill | last post by:
I replaced AddNew statments with INSERT INTO, but am unable to write to the same tables. Foreign keys violations are the main errors. Why are these occuring ? Before: set rs3=...
6
by: Robin Lawrie | last post by:
Hi, Looking for some help here! I'm adding records to a SQL 2000 DB using the objRS.AddNew and objRS.Update methods. What I'd like to do is determine the new primary key value of the added...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
by: durga2005 | last post by:
Hi In my webgrid I have three columns namely “Type” and “Category” and “code” .But while inserting new record I will not enter “Code” Value since it is automatically generated. When I click the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...
0
isladogs
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...

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.