dcsimg
Results 1 to 5 of 5

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2018
    Posts
    10

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,051

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2018
    Posts
    10

    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,067

    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
    New Member
    Join Date
    Jul 2018
    Posts
    10

    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
  •  



Featured


Click Here to Expand Forum to Full Width