Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How to update selected rows in datagridview
Mahmoud Fadl
Nov 18 2017 6:42 AM
201
Reply
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 !!!
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to connect mobile cam over the internet from c#
Datagridview update rows with Dapper