TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mahmoud Fadl
1.4k
319
12.4k
How to update selected rows in datagridview
Nov 18 2017 6:42 AM
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 !!!
Reply
Answers (
1
)
How to connect mobile cam over the internet from c#
Datagridview update rows with Dapper