How to update specific row using checkbox?












0















This is what I've tried. This works for checkbox value only and all displayed data will be updated.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub


Expected output: update only when changing the specific value of checkbox.










share|improve this question























  • It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

    – jmcilhinney
    Nov 21 '18 at 7:26
















0















This is what I've tried. This works for checkbox value only and all displayed data will be updated.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub


Expected output: update only when changing the specific value of checkbox.










share|improve this question























  • It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

    – jmcilhinney
    Nov 21 '18 at 7:26














0












0








0








This is what I've tried. This works for checkbox value only and all displayed data will be updated.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub


Expected output: update only when changing the specific value of checkbox.










share|improve this question














This is what I've tried. This works for checkbox value only and all displayed data will be updated.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub


Expected output: update only when changing the specific value of checkbox.







vb.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 6:44









Ferenee EroesFerenee Eroes

31




31













  • It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

    – jmcilhinney
    Nov 21 '18 at 7:26



















  • It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

    – jmcilhinney
    Nov 21 '18 at 7:26

















It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

– jmcilhinney
Nov 21 '18 at 7:26





It should be fairly obvious that if you want to do something for a row only IF it is checked then you need an If statement in there somewhere. This is why I tell people to work out the logic they want to implement before they start writing any code to implement it. If you had done that then there would have to be some check in that logic for whether the row was checked or not, so you would have to implement that logic in your code.

– jmcilhinney
Nov 21 '18 at 7:26












1 Answer
1






active

oldest

votes


















0














Do you mean that you want to update only the row that have checkboxes turned ON?
If so, it can be determined by the value of the checkbox cell.



For example, like this.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
If Convert.ToBoolean(row.Cells("your checkbox column name").Value) Then
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()
End If

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub





share|improve this answer
























  • Thank you! i forgot i put FalseValue and TrueValue in cb column.

    – Ferenee Eroes
    Nov 21 '18 at 8:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406570%2fhow-to-update-specific-row-using-checkbox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Do you mean that you want to update only the row that have checkboxes turned ON?
If so, it can be determined by the value of the checkbox cell.



For example, like this.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
If Convert.ToBoolean(row.Cells("your checkbox column name").Value) Then
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()
End If

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub





share|improve this answer
























  • Thank you! i forgot i put FalseValue and TrueValue in cb column.

    – Ferenee Eroes
    Nov 21 '18 at 8:02
















0














Do you mean that you want to update only the row that have checkboxes turned ON?
If so, it can be determined by the value of the checkbox cell.



For example, like this.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
If Convert.ToBoolean(row.Cells("your checkbox column name").Value) Then
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()
End If

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub





share|improve this answer
























  • Thank you! i forgot i put FalseValue and TrueValue in cb column.

    – Ferenee Eroes
    Nov 21 '18 at 8:02














0












0








0







Do you mean that you want to update only the row that have checkboxes turned ON?
If so, it can be determined by the value of the checkbox cell.



For example, like this.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
If Convert.ToBoolean(row.Cells("your checkbox column name").Value) Then
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()
End If

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub





share|improve this answer













Do you mean that you want to update only the row that have checkboxes turned ON?
If so, it can be determined by the value of the checkbox cell.



For example, like this.



 Public Sub updateDGV()



Dim id As String
Dim cb As String
Dim time As String
Dim str As String
Dim mycon As New SqlConnection(ConString)
Try
mycon.Open()
For Each row As DataGridViewRow In dgv.Rows
If Convert.ToBoolean(row.Cells("your checkbox column name").Value) Then
row.Cells(22).Value = Date.Now.ToString("MM/dd/yyyy HH:mm:ss tt")
id = row.Cells(0).Value.ToString
cb = row.Cells(1).Value.ToString
time = row.Cells(22).Value.ToString
str = "UPDATE GuardMonitoring SET EmploymentStatus =@EmpStat,
ModifiedBy =@ModifiedBy, ModifyDate =@ModifyDate WHERE
(Employee_Id =@EmpId)"


Dim cmd As SqlCommand = New SqlCommand(str, mycon)
cmd.Parameters.AddWithValue("@EmpId", SqlDbType.VarChar).Value = id
cmd.Parameters.AddWithValue("@EmpStat", SqlDbType.VarChar).Value = cb
cmd.Parameters.AddWithValue("@ModifiedBy", SqlDbType.VarChar).Value = UserPass.txtfull2.Text
cmd.Parameters.AddWithValue("@ModifyDate", SqlDbType.VarChar).Value = time
cmd.ExecuteNonQuery()
End If

Next
mycon.Close()
Catch ex As Exception
showmsg.ForeColor = Color.LightCoral
showmsg.Text = "Rows not found!"
MsgBox(ex.Message)
End Try

End Sub






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 7:30









m mukaim mukai

21627




21627













  • Thank you! i forgot i put FalseValue and TrueValue in cb column.

    – Ferenee Eroes
    Nov 21 '18 at 8:02



















  • Thank you! i forgot i put FalseValue and TrueValue in cb column.

    – Ferenee Eroes
    Nov 21 '18 at 8:02

















Thank you! i forgot i put FalseValue and TrueValue in cb column.

– Ferenee Eroes
Nov 21 '18 at 8:02





Thank you! i forgot i put FalseValue and TrueValue in cb column.

– Ferenee Eroes
Nov 21 '18 at 8:02




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406570%2fhow-to-update-specific-row-using-checkbox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)