ASP. net2.0 calls the MySQL Stored Procedure

Source: Internet
Author: User

MySQL has been added to the stored procedure since MySQL 5.0, because it has not been around for a long time. Many people are asking how to establish the stored procedure in MySQL, 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!

Delimiter
$;

 

Drop procedure if exists
'Mytest'. 'mypage' $

 

Create definer = 'root' @ 'localhost' procedure
'Mypage '(

Tablename varchar (100 ),

Fieldsname varchar (100 ),

Pageindex int,

Pagesize int,

Sortname varchar (500 ),

Strwhere varchar (500)

)

Begin

Declare fieldlist varchar (200 );

If fieldsname = ''| fieldsname = NULL then


Set fieldlist = '*';

Else


Set fieldlist = fieldsname;

End if;

If strwhere = ''| strwhere = NULL then


If sortname = ''| sortname = NULL then


Set @ strsql = Concat ('select', fieldlist, 'from', tablename, 'limit
', (Pageindex-1) * pagesize,', ', pagesize );


Else

Set @ strsql = Concat ('select', fieldlist, 'From
', Tablename, 'ORDER BY', sortname, 'limit
', (Pageindex-1) * pagesize,', ', pagesize );


End if;

Else


If sortname = ''| sortname = NULL then

Set
@ Strsql = Concat ('select', fieldlist, 'from', tablename, 'where', strwhere ,'
Limit ', (pageindex-1) * pagesize,', ', pagesize );


Else

Set
@ Strsql = Concat ('select', fieldlist, 'from', tablename, 'where', strwhere ,'
Order by ', sortname, 'limit', (pageindex-1) * pagesize,', ', pagesize );


End if;

End if;

Prepare stmt1 from @ strsql;

Execute stmt1;

Deallocate prepare stmt1;

End $

 

Delimiter; $

ASP. net2.0 call method. Next time .......

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.