本文介绍了过程或函数"DeleteInfo"需要未提供的参数"@s_id".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似类型的问题,但这一次是使用gridview中的存储过程进行更新/删除:

Similar type of problem but this time for update/delete using stored procedures in gridview:

<asp:GridView runat="server" ID="gv1" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
           OnRowEditing="edit" OnRowUpdating="update" OnRowDeleting="delete" <asp:GridView>



代码(.cs):-



Code(.cs):-

public void delete(object sender, GridViewDeleteEventArgs e)
        {
            SqlConnection conn = new SqlConnection(str_con);
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("DeleteInfo", conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.Add("@s_id", SqlDbType.Int, 10, "s_id");//<----s_id is not primary key
            cmd1.ExecuteNonQuery();
            BindData();
            conn.Close();
        }


存储过程:-


Stored procedure:-

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[DeleteInfo]
(
    @s_id int
)
as
begin
delete from info where s_id=@s_id
end

推荐答案

public void delete(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(gv1.Rows[e.RowIndex].Cells[4].Text);
            SqlConnection conn = new SqlConnection(str_con);
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("DeleteInfo", conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.Add("@s_id", SqlDbType.Int).Value = id;//CHANGE IN THIS LINE
            cmd1.ExecuteNonQuery();
            BindData();
            conn.Close();
        }


int idToDelete = 29;
public void delete(object sender, GridViewDeleteEventArgs e)
        {
            SqlConnection conn = new SqlConnection(str_con);
            conn.Open();
            SqlCommand cmd1 = new SqlCommand("DeleteInfo", conn);
            cmd1.CommandType = CommandType.StoredProcedure;
            cmd1.Parameters.AddWithValue("@s_id", idToDelete);//user with ID 29 will be deleted.
            cmd1.ExecuteNonQuery();
            BindData();
            conn.Close();
        }



如果这解决了您的问题,请标记为答案并投票5

问候,
爱德华



Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard


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

10-31 05:45