日期:2014-05-19  浏览次数:20455 次

一个简单的存储过程
以下代码是我在查询分析器中执行的!没有问题,但我不知道asp.net中怎样去读取这个过程.请大家帮忙
declare   @isresult   smallint
set   @isresult=2
execute   st_uponline   '1 ',@isresult   output
print   @isresult

------解决方案--------------------
SqlConnection myConnection = new SqlConnection(DBConnectionString.ConnectionString);
SqlCommand myCommand = new SqlCommand( "Pr_GetUsers ",myConnection);
//調用存儲過程
myCommand.CommandType = CommandType.StoredProcedure;
SqlDataReader dr = null;
try
{
myConnection.Open();
}
catch(Exception ex)
{
throw new MyException( "10001 ", "錯誤! ",ex);
}
try
{
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(Exception ex)
{
throw new MyException( "10001 ",ex.Message,ex);
}

return dr;

這是調用存儲過程的代碼。你參考一下吧
------解决方案--------------------
asp.net中 借助 ado.net 来读的。
比如说有个叫:DbDataAdapter 类

------解决方案--------------------
try

Public Function UpdateOnlineInfo(ByVal userid As String) As Integer
Dim condb As SqlConnection
condb = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings( "constr "))
condb.Open()
Dim selestr As SqlCommand
selestr = New SqlCommand( "st_uponline ", condb)
selestr.CommandType = CommandType.StoredProcedure
sqlCmd.Parameters.Add( "@userid ", userid);
sqlCmd.Parameters.Add( "@isresult ", SqlDbType.SmallInt);
sqlCmd.Parameters[ "@isresult "].Direction = ParameterDirection.Output;
sqlCmd.ExecuteNonQuery();
Dim bs As Integer
bs = sqlCmd.Parameters[ "@isresult "].Value

Return bs
condb.Close()
End Function 'UpdateOnlineInfo