vb.net调用存储过程
CREATEPROCEDUREALL_USERINFO@upidint,@nintasdeclare@strvarchar(200)set@str='selecttop'...
CREATE PROCEDURE ALL_USERINFO
@upid int,
@n int
as
declare @str varchar(200)
set @str='select top '+@n+' id,name from hunli where upid=@upid order by id desc'
exec(@str)
GO
-----------------------存储过程 --------------------------------
Public Function selectall(ByVal n As Integer, ByVal upid As Integer) As DataSet
Dim sql As String = "ALL_USERINFO"
Dim conn As SqlConnection = connection(connstr)
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
addsqlparamer(cmd, m_userinfo.dbparam_upid, SqlDbType.Int, upid)
addsqlparamer(cmd, "@n", SqlDbType.Int, n)
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
Try
conn.Open()
sda.Fill(ds, "hunli")
Return ds
Catch ex As Exception
Finally
cmdclose(cmd)
connclose(conn)
End Try
'
End Function
Public Sub addsqlparamer(ByRef cmd As SqlCommand, ByVal dbparam As String, ByVal dbtype As SqlDbType, ByVal value As Object)
cmd.CommandType = CommandType.StoredProcedure
Dim sqlparam As SqlParameter = New SqlParameter(dbparam, dbtype)
sqlparam.Value = value
cmd.Parameters.Add(sqlparam)
End Sub
Public Function selectall(ByVal n As Integer, ByVal upid As Integer) As DataSet
Return sqluserinfo.selectall(n, upid)
End Function
Private Sub userinfodatabind(ByVal n As Integer, ByVal upid As Integer)
Dim ds As New DataSet
Dim blluserinfo As DLL.d_userinfo = New DLL.d_userinfo
ds = blluserinfo.selectall(n, upid)
Me.getuserinfo.DataSource = ds
Me.getuserinfo.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
userinfodatabind(2, 3)
End Sub
这段存储过程用三层架构调用的,, 执行后不报错 但是执行后为空白 展开
@upid int,
@n int
as
declare @str varchar(200)
set @str='select top '+@n+' id,name from hunli where upid=@upid order by id desc'
exec(@str)
GO
-----------------------存储过程 --------------------------------
Public Function selectall(ByVal n As Integer, ByVal upid As Integer) As DataSet
Dim sql As String = "ALL_USERINFO"
Dim conn As SqlConnection = connection(connstr)
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
addsqlparamer(cmd, m_userinfo.dbparam_upid, SqlDbType.Int, upid)
addsqlparamer(cmd, "@n", SqlDbType.Int, n)
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
Try
conn.Open()
sda.Fill(ds, "hunli")
Return ds
Catch ex As Exception
Finally
cmdclose(cmd)
connclose(conn)
End Try
'
End Function
Public Sub addsqlparamer(ByRef cmd As SqlCommand, ByVal dbparam As String, ByVal dbtype As SqlDbType, ByVal value As Object)
cmd.CommandType = CommandType.StoredProcedure
Dim sqlparam As SqlParameter = New SqlParameter(dbparam, dbtype)
sqlparam.Value = value
cmd.Parameters.Add(sqlparam)
End Sub
Public Function selectall(ByVal n As Integer, ByVal upid As Integer) As DataSet
Return sqluserinfo.selectall(n, upid)
End Function
Private Sub userinfodatabind(ByVal n As Integer, ByVal upid As Integer)
Dim ds As New DataSet
Dim blluserinfo As DLL.d_userinfo = New DLL.d_userinfo
ds = blluserinfo.selectall(n, upid)
Me.getuserinfo.DataSource = ds
Me.getuserinfo.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
userinfodatabind(2, 3)
End Sub
这段存储过程用三层架构调用的,, 执行后不报错 但是执行后为空白 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询