+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Check for existing data in field using SP

  1. #1
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Check for existing data in field using SP

    Hi people
    I have a registration form, where i need unique email id from users.
    Right now i have the Stored Procedure to insert data, can anybody help me to modify it to do that check in the SP only, i think it can be done.
    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_Register`(
       In FirstName varchar(50),
       in LastName varchar(50),
       in EmailId varchar(100),
       in Gender varchar(20),
       in Mobile varchar(25),
       in Pswd varchar(20))
    BEGIN
       Insert into tblUserMaster (First_Name, Last_Name, Email_Id, User_Gender, User_Mobile,
       Registration_Date, LastLogin_Date, User_Pswd)
       Values (FirstName, LastName, EmailId, Gender, Mobile, now(), now(), Pswd);
    END
    
    MySql
    VS.NET 2005


    Thanx

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Micky, should be something like this:

    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_Register`(
       In FirstName varchar(50),
       in LastName varchar(50),
       in EmailId varchar(100),
       in Gender varchar(20),
       in Mobile varchar(25),
       in Pswd varchar(20))
    BEGIN
       IF NOT EXISTS(SELECT Email_Id FROM tblUserMaster WHERE Email_Id = EmailId) THEN
           Insert into tblUserMaster (First_Name, Last_Name, Email_Id, User_Gender, User_Mobile,
           Registration_Date, LastLogin_Date, User_Pswd)
           Values (FirstName, LastName, EmailId, Gender, Mobile, now(), now(), Pswd);
       END IF;
    END
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    thanx for that J, i'll check it.......but rite now something other urgent has come up
    i'll get back to u on this in couple of days

  4. #4
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    J, that seem to work
    now the second question which is, now can i get the status to my .net application that whether the record was added or not!!

    If not then i'll have to tell user that the email already exists!!
    Btw, do u think thats how it shud be done??
    Thanx

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    What do you mean by getting the status? You mean whether the INSERT was succesful or not?

  6. #6
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    yes RR, i mean if the email id already exists in db, then it wont insert and will have to let user know that he needs to enter another one.

    and the insert is successful, then also i shud know so that i can redirect him accordingly!!

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    You can use an OUT parameter to send a value back.

    If you just need to know if it was successul, you cuold have a CHAR field that returns Y or N depending on if it was successful. It's been a while since I did it, but possibly something like this:-
    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_Register`(
       In FirstName varchar(50),
       in LastName varchar(50),
       in EmailId varchar(100),
       in Gender varchar(20),
       in Mobile varchar(25),
       in Pswd varchar(20),
       Out Result CHAR(1))
    BEGIN
       IF NOT EXISTS(SELECT Email_Id FROM tblUserMaster WHERE Email_Id = EmailId) THEN
           Insert into tblUserMaster (First_Name, Last_Name, Email_Id, User_Gender, User_Mobile,
           Registration_Date, LastLogin_Date, User_Pswd)
           Values (FirstName, LastName, EmailId, Gender, Mobile, now(), now(), Pswd);
           Result="Y";
       ELSE
           Result="N";
       END IF;
    END
    
    I think in your .NET code, you create an instance of a parameter and set it to the OUT parameter from the SP.

    Hope that helps.

  8. #8
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    thanx RR, let me try

  9. #9
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    ok i have to change SP little to do this
    Code:
    CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_Register`(
       In FirstName varchar(50),
       in LastName varchar(50),
       in EmailId varchar(100),
       in Gender varchar(20),
       in Mobile varchar(25),
       in Pswd varchar(20),
       out Result varchar(1))
    BEGIN
       IF NOT EXISTS(SELECT Email_Id FROM tblUserMaster WHERE Email_Id = EmailId) THEN
           Insert into tblUserMaster (First_Name, Last_Name, Email_Id, User_Gender, User_Mobile,
           Registration_Date, LastLogin_Date, User_Pswd)
           Values (FirstName, LastName, EmailId, Gender, Mobile, now(), now(), Pswd);
           Set Result="Y";
       ELSE
           Set Result="N";
       END IF;
    END
    
    but now i cant figure how to get it in my .net code
    need help

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I think it should be something like:-
    Code:
    Dim ResultParam as New MySqlParameter
    ResultParam.Direction = Data.ParameterDirection.Output
    ResultParam.ParameterName = "Result"
    .
    .
    ' execute command
    .
    .
    Dim result as String = ResultParam.Value
    

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Check if result set is empty
    By noFriends in forum PHP Development
    Replies: 9
    Last Post: July 8th, 2011, 10:06 AM
  2. Capture field name
    By Rebelle in forum ASP Development
    Replies: 13
    Last Post: October 7th, 2008, 02:33 PM
  3. Field that is a link (rs) and/or text field question
    By Rebelle in forum ASP Development
    Replies: 14
    Last Post: August 12th, 2008, 09:43 AM
  4. Replies: 5
    Last Post: June 25th, 2008, 09:07 AM
  5. Help with Updating field
    By Rebelle in forum Microsoft Access
    Replies: 5
    Last Post: April 1st, 2008, 07:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO