Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Identity field doesn't increment using .NET application (in development)

Posted on 2007-04-07
4
Medium Priority
?
201 Views
Last Modified: 2010-03-19
Hello.

This one kills me!

I am building a .NET application that for managing a database (SQL Server Express 2005).
In my database I have several tables, two of which (for the sake of presenting the problem) are "Patients" and "Therapists".
Both tables are built similarly; There is a PatientSID (PK, int, not null) and a TherapistSID (PK, int, not null); Both are defined as Identity, with an Identity seed of 1, and an Identity Increment of 1.

In my application, I have two forms: (you guessed right...) "Patients" and "Therapists".
On the forms I'm using auto-generated Navigation Bars (made by dragging the accordant table from the Data Source Explorer window to its form), for retrieving, adding, editing and deleting data in my database.
The two forms, like the two tables in the database, were built the same (more then once, I must say...)!!

Now, the problem:
When trying to add a record to the "Patients" form (by using the "Add" and "Save" buttons on the Navigation Bar), the record is being added to the "Patients" table just fine.
For some reason, when trying to add a record to the "Therapists" table, using the "Therapists" form (again by using the "Add" and "Save" buttons on the Navigation Bar), the record is not being added, because the "TherapistSID" is not incrementing, and I get an error message, saying that the "TherapistSID" doesn't allow NULLs.

The code running (and failing...) for the action of saving the new added record is:

Private Sub TherapistsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles        TherapistsBindingNavigatorSaveItem.Click

        Me.Validate()
        Me.TherapistsBindingSource.EndEdit()                                                              ' This is where it fails!
        Me.TherapistsTableAdapter.Update(Me.HW1DataSet.Therapists)

End Sub

For the "Patients", the code is identical.

BTW, When adding a record directly into the table, in the SQL Server environment, it works just fine!
What's going on??

Please help.
Lior.
0
Comment
Question by:liorim2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18869132
all you posted looks fine. however, there must be a small configuration problem, so that the controls do not "know" about the PK field to be of type identity
for example, just make sure you look at the right database...
0
 

Author Comment

by:liorim2
ID: 18869168
what "controls" do not "know" about the PK field to be.........?
do you mean, controls in my application?
let me remind what i wrote in my first post: "BTW, When adding a record directly into the table, in the SQL Server environment, it works just fine!".

Lior.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18869173
I speak about the navigator bar?
0
 

Author Comment

by:liorim2
ID: 18869702
Bugs, Bugs, Bugs...
Well, the problem was with the RecordSet. After killing it and rebuilding it, the problem is gone.
Thanks anyway, AngelIII, for trying.
0

Featured Post

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question