I have finally gotten past the errors but now I ham having issue with my db not being update with my datgridview data. Sorry I am a newbie here and really don't know why it is not updating.
protected void gvKeyPersonnel_RowUpdating(object sender, EventArgs e) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; conn.Open(); // SqlDataReader myReader = null; // myReader = cmd.ExecuteReader();
foreach (GridViewRow row in gvKeyPersonnel.Rows)
{
cmd.Parameters.Clear();
cmd.CommandText = @"UPDATE SP2010_EDCStaffing_AppDB.dbo.CMS_Key_Personnel SET Name = @Name, VDCIDIQ = @VDCIDIQ, VDCFFS = @VDCFFS, VDCHIM = @VDCHIM, VDCWEBHOSTING = @VDCWEBHOSTING, VDCCWF = @VDCCWF WHERE ID = @id";
cmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvKeyPersonnel.DataKeys[row.RowIndex].Values[0]));
cmd.Parameters.AddWithValue("@Name", row.Cells[1].Text);
cmd.Parameters.AddWithValue("@VDCIDIQ", row.Cells[2].Text);
cmd.Parameters.AddWithValue("@VDCFFS", row.Cells[3].Text);
cmd.Parameters.AddWithValue("@VDCHIM", row.Cells[4].Text);
cmd.Parameters.AddWithValue("@VDCWEBHOSTING", row.Cells[5].Text);
cmd.Parameters.AddWithValue("@VDCCWF", row.Cells[6].Text);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
}
}
int @id = Convert.ToInt32(gvKeyPersonnel.DataKeys[row.RowIndex].Values[0]);
? this will not add the parameter to your command object instead docmd.Paramaters.AddWithValue("@id", Convert.ToInt32(gvKeyPersonnel.DataKeys[row.RowIndex].Values[0]));
do the similar for@name
parameter as well. – Habibconn.Close();
the using handles that for you when doing auto disposal – MethodManValues[1]
exists? – Bart van Nierop