I have a datagridview and it is bound to a database. When i click one of its cell to update its value, actually what happens is that the value of that particular cell is updated but the values of the same row is also updated to null. What do i do so that the values of the same row does not updates to null but it remains as they are?
My Code :
int quantityColumnIndex = 0;
string particularColumnIndex = "";
int rateColumnIndex = 0;
private void buttonUpdate_Click(object sender, EventArgs e)
{
{
string SQL = "Update OrderLineItems set Quantity = " + quantityColumnIndex +
", Particular = '" + particularColumnIndex +
"', Rate = " + rateColumnIndex + " where OrderLineItems.Id = " + Id;
result = dm.ExecuteActionQuery(SQL);
}
if (result > 0)
{
MessageBox.Show("Record Updated Successfully", "Update Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void dataGridViewOrderDetails_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
quantityColumnIndex = Convert.ToInt32(dataGridViewOrderDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
}
if (e.ColumnIndex == 2)
{
particularColumnIndex = dataGridViewOrderDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}
if (e.ColumnIndex == 3)
{
rateColumnIndex = Convert.ToInt32(dataGridViewOrderDetails.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
}
}
Help required
There is a problem in a query. This has been solved 🙂