过程或函数'INSERTMARKS'需要参数'@i',这是未提供的。 [英] Procedure or function 'INSERTMARKS' expects parameter '@i', which was not supplied.

查看:95
本文介绍了过程或函数'INSERTMARKS'需要参数'@i',这是未提供的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

i制作了一个名为INSERTMARKS的存储过程,如下所示





hi everybody.
i made a stored procedure named "INSERTMARKS" which is like below


USE [School]
GO
/****** Object:  StoredProcedure [dbo].[INSERTMARKS]    Script Date: 12/21/2012 13:57:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		VARUN
-- Create date: 21/12/2012
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[INSERTMARKS] 
	-- Add the parameters for the stored procedure here
	@name varchar(50),
	@sub varchar (50),
	@m tinyint,
	@i smallint output,
	@s smallint output
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT @i=Roll_no from student where Name=@name;
	select @s=Subject_ID from subject where subject_name=@sub;
	insert into marks values(@i,@s,@m);
END





程序运行正常在sql server.but当我试图通过c#code.Its执行它显示错误。代码如下:



错误:::程序或功能' 'INSERTMARKS''需要参数''@ i'',这是没有提供的。







The procedure is working fine in sql server.but when i am trying to execute it via c# code.Its showing an error.The code is below:

error:::Procedure or function ''INSERTMARKS'' expects parameter ''@i'', which was not supplied.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


public partial class marks : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string conn = "Data Source=.;Initial Catalog=School;Integrated Security=True";
        SqlConnection con = new SqlConnection(conn);
        con.Open();
        SqlCommand cmd = new SqlCommand("INSERTMARKS",con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "INSERTMARKS";
        cmd.Parameters.Add("@name",SqlDbType.VarChar).Value=DropDownList1.SelectedValue.Text;
       cmd.Parameters.Add("@sub",SqlDbType.VarChar).Value=DropDownList2.SelectedValue;
        cmd.Parameters.Add("@m",SqlDbType.TinyInt).Value=TextBox3.Text;
       // cmd.Parameters.Add("@i", SqlDbType.SmallInt);
        //cmd.Parameters.Add("@s", SqlDbType.SmallInt);
        cmd.ExecuteNonQuery();
        con.Close();

        Response.Redirect("Default.aspx");
        
    }
}

推荐答案

或许,如果您删除了评论标记:

Perhaps, if you removed the comment markers:
// cmd.Parameters.Add("@i", SqlDbType.SmallInt);
//cmd.Parameters.Add("@s", SqlDbType.SmallInt);



所以它读取:


so it read:

cmd.Parameters.Add("@i", SqlDbType.SmallInt).VAlue = myIParam;
cmd.Parameters.Add("@s", SqlDbType.SmallInt).Value = mySParam;

也许它不会抱怨你没有提供你告诉它需要的参数吗?

Perhaps it wouldn''t complain that you aren''t providing the parameters you told it it needed?


你已经在你的存储过程中声明了参数

You have declared parameters in your stored procedure
@i smallint output,
@s smallint output





并且你没有传递两个参数的值而SQL正在期待两个参数。所以,传递两个参数的值。



谢谢



and you are not passing values for both parameters and the SQL is expecting both parameters. so, pass values for both parameter.

Thanks


这篇关于过程或函数'INSERTMARKS'需要参数'@i',这是未提供的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆