469,612 Members | 2,665 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

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 1617
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by pillmill | last post: by
6 posts views Thread by Robin Lawrie | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.