How to update specific row using checkbox?
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
add a comment |
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
It should be fairly obvious that if you want to do something for a row only IF it is checked then you need anIf
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
add a comment |
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
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
vb.net
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 anIf
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
add a comment |
It should be fairly obvious that if you want to do something for a row only IF it is checked then you need anIf
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
add a comment |
1 Answer
1
active
oldest
votes
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
Thank you! i forgot i put FalseValue and TrueValue in cb column.
– Ferenee Eroes
Nov 21 '18 at 8:02
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Thank you! i forgot i put FalseValue and TrueValue in cb column.
– Ferenee Eroes
Nov 21 '18 at 8:02
add a comment |
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
Thank you! i forgot i put FalseValue and TrueValue in cb column.
– Ferenee Eroes
Nov 21 '18 at 8:02
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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