Hi, this first topic for me here
I'm happy to join with you, I want to update selected rows in datagridview based condition
with not editting rows in datagridview , and count selected rows in messagebox
i'ts not problem for me but the real problem the selected rows not count correctly and not updated correctly
i don't know where problem
The code below
- List selectedRows = (from row in DGVweight.Rows.Cast()
- where Convert.ToBoolean(row.Cells[0].Value) == true
- select row).ToList();
-
- if (selectedRows.Count > 0)
- {
- if (MessageBox.Show(string.Format("Will be delivered Total {0} reels to Inventory ", selectedRows.Count), "Confirmation Delivered to Inventory", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- try
- {
- DataAccessLayer.Open();
- foreach (DataGridViewRow row in selectedRows)
- {
- using (SqlConnection con = new SqlConnection(DataAccessLayer.con))
- {
- using (SqlCommand cmd = new SqlCommand("UPDATE Weights set Status=@Delivered , DeliveryDate= @Date, UserName=@UserName WHERE ReelID = @ReelID", DataAccessLayer.cn))
- {
- cmd.CommandType = CommandType.Text;
- cmd.Parameters.AddWithValue("@Delivered", "Delivered");
- cmd.Parameters.AddWithValue("@Date", dateTimePicker1.Value);
- cmd.Parameters.AddWithValue("@ReelID", row.Cells["ReelID"].Value);
- cmd.Parameters.AddWithValue("@UserName", GlobalVariables.CurrentUser);
- cmd.ExecuteNonQuery();
- }
-
- }
- }
- DataAccessLayer.Close();
Thank you.
image 1
image 2 !!!