一个小白不会用SqlHelper调用存储过程!高人救命!
前提:我从网上下了个SqlHelper类 C#的用工具转成了VB,放在了我的APP_Code 名为SqlHelper.vb
然后程序中我Dim db As New SqlDbHelper 来用
第一参数connectionString 我发现sqlhelper里面是私有的 没法调用啊 反正我也搞不清楚用的对不对 代码我都贴出来
有空的达人帮我看看把!
我的用法(抄别人的代码)
Repeater1.DataSource = db.ExecuteReader(connectionString, CommandType.StoredProcedure, "sp_Util_Sort_SELECT", New SqlParameter("@sField ", "SortID,SortName,SortParentID,SortParentPath,SortOrder"), New SqlParameter("@sTable ", "tbTempSort"), New SqlParameter("@iSortID ", 4), New SqlParameter("@iCond", 1)) Repeater1.DataBind()
/*输出目录树调用示范:EXEC sp_Util_Sort_SELECT 'SortID,SortName,SortParentID,SortParentPath,SortOrder','tbTempSort',4,1输入: 1.字段名(字段名不能为SortNameTree,SortMoveUp,SortMoveDown) 2.表名 3.欲调用的分类ID(0或者此ID不存在,即调用所有) 4.条件(1包含本级ID和所有下级ID,2包含本级ID和子ID,3不包含本级ID的所有下级ID,4不包含本级ID的子ID)返回:记录集*/CREATE PROCEDURE sp_Util_Sort_SELECT( @sField varchar(255), @sTable varchar(50), @iSortID int, @iCond tinyint)ASBEGIN SET NOCOUNT ON DECLARE @s nvarchar(4000),@s1 varchar(1000),@s2 varchar(1000) SET @s1=CAST(@iSortID AS varchar(10)) SELECT @sField=(CASE WHEN LEN(@sField)>0 THEN @sField+',' ELSE '' END) IF @iSortID>0 BEGIN SET @s='SELECT @s2=SortParentPath FROM '+@sTable+' WHERE SortID='+@s1 EXEC sp_executesql @s,N'@s2 varchar(4000) OUT',@s2 OUT IF @s2 IS Null GOTO step1 ELSE GOTO step2 END ELSE BEGIN GOTO step1 END step1: BEGIN SELECT @s2=',' SELECT @s1=(CASE @iCond WHEN 2 THEN ' WHERE SortParentID=0' WHEN 4 THEN ' WHERE SortParentID=0' ELSE '' END) GOTO step3 END step2: BEGIN SELECT @s1=(CASE @iCond WHEN 2 THEN ' WHERE SortID='+@s1+' OR SortParentID='+@s1 WHEN 3 THEN ' WHERE CHARINDEX('','+@s1+','',SortParentPath)>0' WHEN 4 THEN ' WHERE SortParentID='+@s1 ELSE ' WHERE SortID='+@s1+' OR CHARINDEX('','+@s1+','',SortParentPath)>0' END) GOTO step3 END step3: SET @s='SELECT '+@sField+' dbo.fn_Sort_Tree(SortName,SortParentPath,'''+@s2+''',(SELECT COUNT(0) FROM '+@sTable+' B WHERE B.SortParentID=A.SortParentID AND B.SortOrder>A.SortOrder)) AS SortNameTree,(SELECT COUNT(0) FROM '+@sTable+' B WHERE B.SortParentID=A.SortParentID AND B.SortOrder<A.SortOrder) AS SortMoveUp,(SELECT -COUNT(0) FROM '+@sTable+' B where B.SortParentID=A.SortParentID AND B.SortOrder>A.SortOrder) AS SortMoveDown FROM '+@sTable+' A '+@s1+' ORDER BY SortOrder ASC' EXEC (@s)ENDGO