i am deleting a row from grid view my code is as follows. I got an exception i.e.
Index was out of range. Must be non negative and less then the size of the collection. Parameter name: INDEX
Code:
private void bindingNavigatorDeleteItem_Click()
{
try
SqlDataAdapter da;
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(@"Data Source=HARIS\SQLEXPRESS;Initial Catalog=Nesk;Integrated Security=True");
da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("sp_Nsk_PromoCriteriaDelete");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@promoID", SqlDbType.VarChar).Value = System.Convert.ToInt32(nsk_PromoCriteriaDataGridView.SelectedRows[0].Cells[0].Value);
cmd.Connection = conn;
da.SelectCommand = cmd;
da.Fill(ds);
conn.Close();
}
catch(Exception ex)
MessageBox.Show(ex.Message);
Stored Procedure:
ALTER PROCEDURE [dbo].[sp_Nsk_PromoCriteriaDelete]
@PromoID varchar(20)
AS BEGIN
SET NOCOUNT ON;
delete from Nsk_PromoCriteria where PromoId = @PromoID
END