I'm using similar code for adding and editing records in my app, but when I try to do a delete, I get the following error: "Procedure or function 'usp_Delete_Image' expects parameter '@Image_ID', which was not supplied." Also, if I try to delete the second to the last row in the datagridview, it givese me the ID for the last row...If I try to delete the last row, it gives me the ID for the second to last row...
Here is the stored procedure I'm calling in SQL Server:
ALTER PROCEDURE [dbo].[usp_Delete_Image]
@Image_ID INT
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM dbo.Images
WHERE Image_ID = @Image_ID
END
Here is the code that gets the selected ID from the datagridview and then calls the DataAccess class for deleting the row:
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
int ImageID = Convert.ToInt32(dgvImages.GetData(dgvImages.Row, 1));
DataAccess.usp_Delete_Image((int)ImageID);
LoadGridView();
}
And heres the DataAccess code that calls the stored procedure:
public static int usp_Delete_Image(int Image_ID)
{
SqlCommand sp = new SqlCommand("usp_Delete_Image", cs);
sp.Parameters.AddWithValue("@Image_ID", Image_ID);
if (cs.State == ConnectionState.Closed)
cs.Open();
int i = sp.ExecuteNonQuery();
cs.Close();
return i;
}

New Topic/Question
Reply



MultiQuote




|