存储过程如下:
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype
GO
------------------
我要用count.text得到@comcount的值,怎么做??
...全文
41825打赏收藏
50分求存储过程返回值
存储过程如下: CREATE PROCEDURE pmc_count(@comtype varchar(50)) as declare @comcount int set @comcount=(select count(*) from pmc where comtype=@comtype GO ------------------ 我要用count.text得到@comcount的值,怎么做??
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype)
return @comcount
GO
好象是这样吧.你试试
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
select @comcount=(select count(*) from pmc where comtype=@comtype)
select @comcount
select * from pmc
GO
给你多个结果集返回的参考
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
select @comcount=(select count(*) from pmc where comtype=@comtype)
select * from pmc
GO
======================================================================
Dim Connection As SqlConnection = cn
Dim cm As SqlCommand = New SqlCommand("pmc_count", cn)
cm.CommandType = CommandType.StoredProcedure
Dim para As New SqlParameter("@comtype", SqlDbType.VarChar, 50)
para.Value = comcount.Text
cm.Parameters.Add(para)
Dim apt As SqlDataAdapter = New SqlDataAdapter(cm)
Dim ds As DataSet = New DataSet
apt.Fill(ds)
Dim count As Integer
count = ds.Tables(0).Rows(0).Item(0)
'ds.Tables(1)为select语句"select * from pmc"返回的结果集
Dim Connection As SqlConnection = cn '确定cn打开
Dim cm As SqlCommand = New SqlCommand("pmc_count", cn)
cm.CommandType = CommandType.StoredProcedure
Dim para As New SqlParameter("@comtype", SqlDbType.VarChar, 50)
para.Value = comcount.Text
cm.Parameters.Add(para)
cm.ExecuteReader()'这个注释掉看看
Dim count As Integer
count = cm.ExecuteScalar()
comcount.Text = count.ToString
cm.Dispose()
--------------------------------
报啥错?
我是要得到多个值.我先一个开始啊..多怕更多错!我试了上面的.还是报错:
Dim Connection As SqlConnection = cn
Dim cm As SqlCommand = New SqlCommand("pmc_count", cn)
cm.CommandType = CommandType.StoredProcedure
Dim para As New SqlParameter("@comtype", SqlDbType.VarChar, 50)
para.Value = comcount.Text
cm.Parameters.Add(para)
cm.ExecuteReader()
Dim count As Integer
count = cm.ExecuteScalar()
comcount.Text = count.ToString
cm.Dispose()
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype
return @comcount
GO
存储过程没写对
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype)
return @comcount
GO
CREATE PROCEDURE pmc_count(@comtype varchar(50))
as
declare @comcount int
set @comcount=(select count(*) from pmc where comtype=@comtype
..
select @comcount '输出
GO
然后执行存储过程,输出到结果集