Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# @sql server中未提供的输出_C#_Sql Server_Stored Procedures - Fatal编程技术网

C# @sql server中未提供的输出

C# @sql server中未提供的输出,c#,sql-server,stored-procedures,C#,Sql Server,Stored Procedures,C#代码: 存储过程: protected void btnsearch_Click(object sender, EventArgs e) { SqlConnection con = Connection.DBconnection(); SqlCommand com = new SqlCommand("sp_studentresult", con); com.CommandType = CommandType.StoredProcedure; com.

C#代码:

存储过程:

protected void btnsearch_Click(object sender, EventArgs e)
{
    SqlConnection con = Connection.DBconnection();   

    SqlCommand com = new SqlCommand("sp_studentresult", con);
    com.CommandType = CommandType.StoredProcedure;

    com.Parameters.AddWithValue("@id", textstudentid.Text);

    SqlDataAdapter adp = new SqlDataAdapter(com);
    DataSet ds = new DataSet();
    adp.Fill(ds);

    if (ds.Tables[0].Rows.Count > 0)
    {                   
        txtid.Text = ds.Tables[0].Rows[0]["id"].ToString();
        txttamil.Text = ds.Tables[0].Rows[0]["Tamil"].ToString();
        txtenglish.Text = ds.Tables[0].Rows[0]["English"].ToString();
        txtmaths.Text = ds.Tables[0].Rows[0]["Maths"].ToString();
        txtscience.Text = ds.Tables[0].Rows[0]["Science"].ToString();
        txtsocialscience.Text = ds.Tables[0].Rows[0]["SocialScience"].ToString();                     
    }

    SqlParameter retval = new SqlParameter("@output", SqlDbType.VarChar, 50);
    retval.Direction = ParameterDirection.Output;
    com.Parameters.Add(retval);

    com.ExecuteNonQuery();

    string Output = retval.Value.ToString();   
}
我不熟悉.net。当我输入学生id并搜索时,我得到

过程或函数sp_studentresult指定的参数太多

我可以知道我在上面的代码中犯了什么错误吗

任何帮助都将不胜感激


谢谢,

存储过程名称不同

    ALTER PROCEDURE sp_studentresult
(
    @id int,
    @output varchar(50) output,
    @id_student varchar(50)
)
AS
begin
SELECT * from studentresult where id_student=@id
End
IF EXISTS (SELECT * FROM student WHERE id=@id_student)
BEGIN
SET @output='EXIST'
END
这里您指的是“sp_studentresult”。插入的存储过程代码为

  SqlCommand com = new SqlCommand("sp_studentresult", con);

显然,这些过程的参数列表应该不同。

这是因为存储过程没有获取所有参数的值, 检查从SqlCommand传递到SP的参数数。
如果可能,请更新存储过程

您缺少必须提供的参数id\u student。 只有标记为输出的参数不需要提供。 像添加@id一样添加它 例如 com.Parameters.AddWithValue(“@id”,Value)


我不确定它的值是多少,所以您可以将正确的值替换为变量值

我打赌,您正在尝试返回sql结果集和输出参数,对吗?如果是,请尝试以下代码:

ALTER PROCEDURE sp_searchupdate

显示存储过程代码请在此处发布存储过程
sp_studentresult
,以便我们知道此存储过程需要哪些参数。顺便问一下,您是否检查了存储过程是否在数据库中?您可以检查一下我的sp吗?thanksSide注意::“在命名过程时避免使用sp_uuu前缀。SQL Server使用此前缀指定系统过程。使用前缀可能会导致应用程序代码中断…”您必须发布sp_studentresult存储过程的代码。如果您发布的存储过程代码为sp_searchupdate,请重新发布。发布sp_studentresult的代码。我无法对您的帖子发表评论,因为我发布了sp_studentresult存储过程。。但现在它显示了未提供的@output..output参数不需要提供,但必须提供所有其他参数。
protected void btnsearch_Click(object sender, EventArgs e)
{
    SqlConnection con = Connection.DBconnection();

    SqlCommand com = new SqlCommand("sp_studentresult", con);
    com.CommandType = CommandType.StoredProcedure;

    com.Parameters.AddWithValue("@id", textstudentid.Text);
    com.Parameters.AddWithValue("@id_student", textIDStudent.Text);
    SqlParameter retval2 = new SqlParameter("@output", SqlDbType.VarChar, 50);
    retval2.Direction = ParameterDirection.Output;
    com.Parameters.Add(retval2);

    SqlDataAdapter adp = new SqlDataAdapter(com);
    DataSet ds = new DataSet();
    adp.Fill(ds);

    if (ds.Tables[0].Rows.Count > 0)
    {
        txtid.Text = ds.Tables[0].Rows[0]["id"].ToString();
        txttamil.Text = ds.Tables[0].Rows[0]["Tamil"].ToString();
        txtenglish.Text = ds.Tables[0].Rows[0]["English"].ToString();
        txtmaths.Text = ds.Tables[0].Rows[0]["Maths"].ToString();
        txtscience.Text = ds.Tables[0].Rows[0]["Science"].ToString();
        txtsocialscience.Text = ds.Tables[0].Rows[0]["SocialScience"].ToString();
    }

    SqlParameter retval = new SqlParameter("@output", SqlDbType.VarChar, 50);
    retval.Direction = ParameterDirection.Output;
    com.Parameters.Add(retval);
    com.Parameters.AddWithValue("@id", textstudentid.Text);
    com.Parameters.AddWithValue("@id_student", textIDStudent.Text);

    com.ExecuteNonQuery();

    string Output = retval.Value.ToString();
}