Sample Code for ASP. NET2.0 to call the MySQL Stored Procedure

Source: Internet
Author: User

The following articles mainly use ASP. the detailed description of the actual operation code for NET2.0 to call the MySQL stored procedure. We all know that MySQL has been added to the stored procedure since 5.0. Since it has not been too long, there are many questions about how to create a MySQL stored procedure.

Next, I have created one as I understand. in asp. the call method in net2.0 is similar to that in SQL, but there is little difference. The following is a paging stored procedure in MySQL. MySQL limite brings us great convenience. do not write too much code!

 
 
  1. DELIMITER $$;  
  2. DROP PROCEDURE IF EXISTS `mytest`.`MyPage`$$  
  3. CREATE DEFINER=`root`@`localhost` PROCEDURE `MyPage`(  
  4. tableName varchar(100),  
  5. fieldsName VARCHAR(100),  
  6. pageIndex int,  
  7. pageSize int,  
  8. sortName VARCHAR(500),  
  9. strWhere varchar(500)  
  10. )  
  11. BEGIN  
  12. DECLARE fieldlist VARCHAR(200);  
  13. if fieldsName=''||fieldsName=null THEN  
  14. set fieldlist='*';  
  15. else  
  16. set fieldlist=fieldsName;  
  17. end if;  
  18. if strWhere=''||strWhere=null then  
  19. if sortName=''||sortName=null then  
  20. set @strSQL=concat('select ',fieldlist,' from ' , tableName,' limit ',(pageindex-1)*pageSize,',',pageSize);  
  21. else  
  22. set @strSQL=concat('select ',fieldlist,' from ' , tableName,' order by ',sortName,' limit ',(pageindex-1)*pageSize,',',pageSize);  
  23. end if;  
  24. else  
  25. if sortName=''||sortName=null then  
  26. set @strSQL=concat('select ',fieldlist,' from ' , tableName,' where ',strWhere,' limit ',(pageindex-1)*pageSize,',',pageSize);  
  27. else  
  28. set @strSQL=concat('select ',fieldlist,' from ' , tableName,' where ',strWhere,' 
    order by ',sortName,' limit ',(pageindex-1)*pageSize,',',pageSize);  
  29. end if;  
  30. end if;  
  31. PREPARE stmt1 FROM @strSQL;  
  32. EXECUTE stmt1;  
  33. DEALLOCATE PREPARE stmt1;  
  34. END$$  
  35. DELIMITER ;$$  

Asp. net2.0 call method. Next time ....... The above content is an introduction to the MySQL stored procedure called by ASP. NET2.0. I hope you will get some benefits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.