存儲過程返回一個值:過程沒有參數和論點提供3
ALTER PROCEDURE [dbo].[spCaller]
AS
BEGIN
DECLARE @URL nvarchar(255);
EXECUTE spBuscarUrl 'MIREX-2017-00001', @url = @URL OUTPUT;
SELECT @URL
END
當我試圖表現出使用ASP.NET的價值,我得到一個錯誤:
Procedure spCaller has no parameters and arguments were supplied
這是我的C#代碼:
try
{
string s = System.Configuration.ConfigurationManager.ConnectionStrings["dba"].ConnectionString;
SqlConnection conexion = new SqlConnection(s);
conexion.Open();
using (SqlCommand cmd = new SqlCommand("spCaller",conexion))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@URL", SqlDbType.NVarChar).Value = Label1.Text.Trim();
object o = cmd.ExecuteScalar();
if(o != null)
{
string id = o.ToString();
lblTitulo.Text = "Completed";
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
的可能的複製[如何使用OUTPUT參數的存儲過程(https://stackoverflow.com/questions/7770924/how-to-use-output - 參數存儲過程) – mjwills
請包含'spBuscarUrl'的源代碼。 – mjwills