-
Re: IF Statement
Ok Did some re-arrange and its working know as I wanted..
But I want ONLY one last thing - after every record update I receive the message;
1 Records inserted or updated...
I want this message to be the sum of all the records updated and should be prompted at the end when an exit button is called..
Code:
Dim RecordsAffected As Integer = 0
Dim Prac_Req As New System.Data.SqlClient.SqlCommand(("Select prac_no, prac_enabled From dbo.TblPracExclude where Prac_no = " & _
DgvPracExcl.Rows(e.RowIndex).Cells(0).Value), conn)
Try
Using Autoreader As System.Data.SqlClient.SqlDataReader = Prac_Req.ExecuteReader()
While Autoreader.Read()
prac_no = Autoreader.GetValue(0)
prac_enabled = Autoreader.GetValue(1)
End While
End Using
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
End Try
If prac_enabled = DgvPracExcl.Rows(e.RowIndex).Cells(3).Value Then
'MsgBox("No Practice need Update", MsgBoxStyle.Information, "VeriSIS")
Else
Try
query = "UPDATE dbo.TblPracExclude SET prac_enabled ='" & _
DgvPracExcl.Rows(e.RowIndex).Cells(3).Value & "' where Prac_No=" & _
DgvPracExcl.Rows(e.RowIndex).Cells(0).Value & ""
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS")
End Try
RecordsAffected = RecordsAffected + 1
End If
If RecordsAffected > 0 Then
MsgBox(RecordsAffected & " Records inserted or updated")
Else
MsgBox("No Records need updating")
End If
End Sub
Can I create a function out of the Rowvalidating() and call it to do the count and prompt a message of the number of records updated?
Thanks
-
Re: IF Statement
He was not passing the rowid, was passing prac_no instead which was causing the problem.
His question was cross posted on VBForums