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
Israel
693
1.3k
219.4k
A simple loop when editing
Aug 29 2019 5:08 AM
Hi Developer,
I need help from you concerning a simple loop.
1) I have a table named Test with three columns (
ColPositive
,
ColNegative
,
ColResult
)
2) On my "Form" I have three components :
txtColPositive
,
txtColNegative,
btnSave
and
dvgTest
When I click on my dvgTest (Datagriviewer) its displaying data selected from the datagridviewer (for this operation its solved!).
Then what I need?
On my
btnSave
I code wrote to update data. But if its update just one row its will not update the right result on the column
ColnResult
. Its wrong!
Then on the first click its update the first row then will updating automatically the rest of the rows until the last one (looping).
Let's show and explain on this table:
ID ColPositive ColNegative ColResult
1 100 0 100
2 0 15 85
3 0 5 80
4 0 0 70
4 50 0 120
5 25 0 145
Explanation:
1) on
col1Positive
, I insert 100 as positive number its will do plus nothing (or "0") its equal to 100
2) on
col1Negative
, I insert 15 as negative number its will do minus that last 100 its equal to 85
... And so on. But its should do a loop until the last record.
3) All the operations loop is coded into
btnSave
4) My update code after to select the right row are here:
private
void
btnSave_Click(
object
sender, EventArgs e)
{
conn =
new
SqlConnection(connstr);
comm =
new
SqlCommand();
conn.Open();
SqlParameter ColPositive =
new
SqlParameter(
"@ColPositive"
, SqlDbType.VarChar);
SqlParameter ColNegative =
new
SqlParameter(
"@ColNegative"
, SqlDbType.VarChar);
SqlParameter ColResult =
new
SqlParameter(
"@ColResult"
, SqlDbType.VarChar);
SqlParameter ID =
new
SqlParameter(
"@ID"
, SqlDbType.Int);
comm.Parameters.Add(ColPositive);
comm.Parameters.Add(ColNegative);
comm.Parameters.Add(ColResult);
comm.Parameters.Add(ID);
ColPositive.Value = txtPositive.Text;
ColNegative.Value = txtNegative.Text;
ColResult.Value = txtResult.Text;
ID.Value = lblID.Text;
comm.Connection = conn;
comm.CommandText =
"UPDATE Test SET ColPositive = @ColPositive, ColNegative = @ColNegative, ColResult = @ColResult WHERE (ID = @ID)"
;
{
if
(MessageBox.Show(
"Are you sure to edit?"
,
"Editing windows"
, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
comm.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
}
}
Reply
Answers (
2
)
System.Net.Socket Error using Azure-Iot-device-read-message
IIS Configuration Issue