I have a form where I can update my data in the datagridview and it will save a log.
My problem is that every time I saved my data it insert all the data in the datagrid.
How will i save data that will only save if i made changes to the datagridview? is that possible?
Here is a snapshot of my UI:
And my code code that saves the data:
//this is the formula for inserting history logs
MySqlConnection conn = new MySqlConnection("Data Source=" + clsSQLcon.sqlServerName + ";port=" + clsSQLcon.sqlPort + ";Initial Catalog =" + clsSQLcon.sqlDatabaseName + ";user id =" + clsSQLcon.sqlUserName + ";password =" + clsSQLcon.sqlPassword + "");
conn.Open();
string query = "INSERT INTO tblhistorylogs(DATE_UPDATED,NAME,LOGS) VALUES" +
"(@Date,@Name,@HistoryLogs)";
MySqlCommand command = new MySqlCommand(query, conn);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (txtPRSSearch.Text.Length <= 3)
{ }
else
{
command.Parameters.AddWithValue("@Date", DateTime.Today.ToString("yyyy-MM-dd"));
command.Parameters.AddWithValue("@Name", "Updated by: " + LoginForm.SetValueForText1 +"\n("+ cbxPRSctrl.Text + "-" + txtPRSSearch.Text +")");
command.Parameters.AddWithValue("@HistoryLogs",
"STATUS: " + Convert.ToString(dataGridView1.Rows[i].Cells[0].Value) + "\n" +
"ITEM NAME: " + Convert.ToString(dataGridView1.Rows[i].Cells[5].Value) + "\n" +
"DATE RECEIVED: " + Convert.ToString(dataGridView2.Rows[i].Cells[0].Value) + "\n" +
"RECEIVED BY: " + Convert.ToString(dataGridView3.Rows[i].Cells[0].Value) + "\n" +
"SUPPLIER: " + Convert.ToString(dataGridView3.Rows[i].Cells[1].Value) + "\n" +
"PO/PCF/PIS: " + Convert.ToString(dataGridView3.Rows[i].Cells[2].Value) + "\n" +
"UNIT COST " + Convert.ToString(dataGridView3.Rows[i].Cells[3].Value) + "\n" +
"AMOUNT: " + Convert.ToString(dataGridView3.Rows[i].Cells[4].Value) + "\n" +
"REF/CV/JV: " + Convert.ToString(dataGridView3.Rows[i].Cells[5].Value) + "\n" +
"DATEPAID: " + Convert.ToString(dataGridView3.Rows[i].Cells[6].Value) + "\n" +
"INCHARGE: " + Convert.ToString(dataGridView3.Rows[i].Cells[7].Value) + "\n" +
"TARGET DATE: " + Convert.ToString(dataGridView3.Rows[i].Cells[8].Value));
command.ExecuteNonQuery();
command.Parameters.Clear();
}
}