472,374 Members | 1,384 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,374 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 1718
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.