Results 1 to 8 of 8
  1. #1
    james432213 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    4

    Adding a new row results displays -1

    Hi, when I add a new employer, the employer ID is displayed as -1, instead of displaying the incremental ID value that is stored in the database. When I restart the application the correct Employer ID is finally displayed. It's like it's not syncing in real-time.



    Click image for larger version. 

Name:	employeeID.png 
Views:	17 
Size:	21.4 KB 
ID:	39021

    Code:
                    newEmployerRow["EmployerName"] = txtAddEmployerName.Text;                   //EmployerName in the Employer table is now equal to its according text box.
                    newEmployerRow["Street Address"] = txtAddEmployerStreetAddress.Text;        //Street Address in the Employer table is now equal to its according text box.
                    newEmployerRow["Suburb"] = txtAddEmployerSuburb.Text;                       //Suburb in the Employer table is now equal to its according text box.
                    newEmployerRow["PhoneNumber"] = txtAddEmployerPhoneNumber.Text;             //PhoneNumber in the Employer table is now equal to its according text box.
    
    
    
    
                    DM.dtEmployer.Rows.Add(newEmployerRow);                             //Add the new Employer row from the data module.
                    DM.updateEmployer();                                                //Update the Employer table from the data module.
                    MessageBox.Show("Employer added successfully", "Success");          //Display a success message.
    
    
                    return;
    Thank you -Let me know if you need any more code.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Do users need to see this ID? Does it really have meaning to them?

    Is this VB.net code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    james432213 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    4
    In this instance, yes, the ID needs to be displayed. It's the requirement of a school assignment.

    It's C# code.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Sorry, don't know C#.

    Is EmployeeID an autonumber field? Is there some way to refresh the form after data sent to table?
    Last edited by June7; 07-06-2019 at 11:23 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    james432213 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    4
    Yes, it's an autonumber field. I've been trying to find a "refresh" solution, but no luck.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Why are you using C# code in an MS Access program?

    Or, if this is for a C# program, why are you asking for help in an MS Access forum?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If bothersome, I would do one or more of the following
    - compact/repair
    - delete the autonumber PK field, save and close table, reopen in design and reinstate the field
    - make sure AN field is set to increment, not random
    - make sure the AN field is not being used in a child/master link
    notwithstanding that AN fields are only meant to be unique and have no assurance that they will all be positive or sequential. In addition, unless the assignment specifies that they must be sequential, why worry about the situation as described? If the assignment creator has stipulated that AN's should increment and be sequential, there is a gap in his/her knowledge about AN's.

    That is all predicated on the assumption that Access tables are involved since that's what this forum is about, and OP indicates version 2016.
    Also -
    - would not use .Text property for form fields if they are bound
    - and wonder if there is any relationship between the listbox (if that's what it is) and the control for the autonumber ID (e.g. is ID linked to any list column?)
    - would probably use requery, not refresh
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    james432213 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    4
    I apologize if my question was not suitable for these forums.

    I have found the solution which was triggered by June7's mentioning of "refresh".

    In my data module class I created a function to clear the dataset then re-filled the data adapter, as such:

    Code:
                dataset.Clear();
                daEmployer.Fill(dataset);
    Thank you for all your guy's help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 07-16-2018, 09:01 AM
  2. Replies: 3
    Last Post: 07-01-2016, 08:11 AM
  3. ADDING Not showing results
    By keiath in forum Forms
    Replies: 5
    Last Post: 02-12-2014, 02:33 PM
  4. Replies: 6
    Last Post: 05-12-2012, 03:13 AM
  5. Replies: 1
    Last Post: 01-10-2011, 11:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums