ASP.NET2.0调用MySql的存储过程
2006-09-21 20:09
381 查看
MYSQL 从5.0开始便加入了存储过程,因为它出现的时间还不是很久,现在有很多都在问,MYSQL存储过程怎么建立,下我就我所理解的建了一个.在asp.net2.0下调用非常方法,跟SQL差不多,但也有少少差别,下面就是MYSQL一个分页的的存储过程;MYSQL的limite给我们带来很大的方便.不要写太多的代码!
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调用方法.下次给出来…….
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调用方法.下次给出来…….
相关文章推荐
- Mybatis调用Mysql存储过程
- MySQL存储过程例子,包含事务,参数,嵌套调用,游标,循环等
- JAVA调用MYSQL存储过程
- php调用mysql存储过程和函数的方法
- mysql存储过程及调用
- mysql的存储过程和触发器的使用 以及php中的调用方法
- mysql存储过程学习及java调用存储过程
- mybatis调用mysql存储过程的例子
- MySQL存储过程相互调用并获得错误码示例
- MySQL存储过程相互调用并获得错误码
- Python简单调用MySQL存储过程并获得返回值的方法
- C#调用MySQL存储过程
- 在mybatis调用mysql的存储过程
- C#中调用mysql存储过程出现的问题
- 实例解析MySQL中的存储过程及存储过程的调用方法
- hibernate调用mysql的存储过程
- MySQL存储过程以及在JAVA中的程序调用
- Mysql存储过程的创建,调用和三种参数类型的解释说明
- aspnet调用mysql存储过程
- php调用mysql存储过程