prateek sharma

prateek sharma

  • NA
  • 6
  • 468

code for audit history of database using update button in DG

May 8 2018 12:43 PM
can any one give me an example for audit history of database using update button in DG.
 
 
i.e.user should know who updated the 1st Row & 50th Row updated by other user in Datagridview. 
 
 
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "Submit")
{
using (OleDbConnection con1 = new OleDbConnection(con))
{
con1.Open();
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con1;
string query1 = ("Update Reports set ID = @id,Comments = @comments,marks = @marks,Reviewer = '" + Environment.UserName + "',ReviewerDate = Now Where(ID = @id)");
cmd.Parameters.AddWithValue("@id", dataGridView1.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@comments", dataGridView1.Rows[i].Cells[5].Value);
cmd.Parameters.AddWithValue("@marks", dataGridView1.Rows[i].Cells[6].Value);
cmd.CommandText = query1;
cmd.ExecuteNonQuery();
}
MessageBox.Show("Comments Submitted", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
 
 code is working but Reviewer & Revieweddate is updating in whole datagridview rows
 
can anyone help?