-
Jul 2nd, 2018, 06:42 AM
#1
Thread Starter
Junior Member
[RESOLVED] Checking duplicate mobile number while editing student's profile
I am currently working on Library Management System. I have a student module with functions such like Add Student, Delete Student, Edit Student, List Students.If profile of student is edited, the mobile number field must be unique in the database. For this I am storing all the mobile numbers in a temporary array and comparing each array item with mobile text box. My problem is if a student's mobile number is not edited (other fields like name are only edited) and I try to save the updated record in my database (by moving record pointer), the student's unedited mobile number is also taken as duplicate value. I mean that my current coding forces the student to change his mobile number if he tries to change any other field also. What I want is that my coding should not compare the text box value with current student's record. Please help
-
Jul 2nd, 2018, 07:49 AM
#2
Re: Checking duplicate mobile number while editing student's profile
Firstly, get rid of your array. All you have to do is query the database for a record with a matching mobile number and without a matching ID, e.g.
Code:
SELECT COUNT(*) Student WHERE MobileNumber = @MobileNumber AND StudentId <> @StudentId
You'll either get 1 or 0 back from that.
-
Jul 2nd, 2018, 11:56 PM
#3
Thread Starter
Junior Member
Re: Checking duplicate mobile number while editing student's profile
Originally Posted by jmcilhinney
Firstly, get rid of your array. All you have to do is query the database for a record with a matching mobile number and without a matching ID, e.g.
Code:
SELECT COUNT(*) Student WHERE MobileNumber = @MobileNumber AND StudentId <> @StudentId
You'll either get 1 or 0 back from that.
Thank you for your help. It worked.
-
Jul 3rd, 2018, 11:10 AM
#4
Re: [RESOLVED] Checking duplicate mobile number while editing student's profile
kommal,
confused by your problem
do you really mean that the following will not succeed
Code:
UPDATE TheTable SET TheField = "aaa" WHERE TheTable.Id=2
if TheField already contains "aaa"
?
do not put off till tomorrow what you can put off forever
-
Jul 4th, 2018, 12:02 AM
#5
Thread Starter
Junior Member
Re: [RESOLVED] Checking duplicate mobile number while editing student's profile
Originally Posted by IkkeEnGij
kommal,
confused by your problem
do you really mean that the following will not succeed
Code:
UPDATE TheTable SET TheField = "aaa" WHERE TheTable.Id=2
if TheField already contains "aaa"
?
Actually I was committing a silly mistake. I was checking only the mobile field but not the id field. Sorry but now I got my mistake. Thanks for your reply
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|