Results 1 to 5 of 5

Thread: [RESOLVED] Checking duplicate mobile number while editing student's profile

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2018
    Posts
    24

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2018
    Posts
    24

    Re: Checking duplicate mobile number while editing student's profile

    Quote Originally Posted by jmcilhinney View Post
    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.

  4. #4
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2018
    Posts
    24

    Re: [RESOLVED] Checking duplicate mobile number while editing student's profile

    Quote Originally Posted by IkkeEnGij View Post
    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
  •  



Click Here to Expand Forum to Full Width