Hi,
I have the following function, which when exceuted doesn't do the following -
a) Update if the checkbox on the datagrid is changed (Cell(3)).
b) Insert data when the prac_no doesn't exist in the database..
Any help will be highly apprecaited
Code:Private Sub UpdatePraclist() Dim conn As SqlConnection = GetDbConnection() Dim cmd As New SqlCommand Dim prac_no As Integer Dim prac_enabled As String = Nothing Dim irow As Integer Dim strFlag As String = "Insert" For irow = 0 To DgvPracExcl.Rows.Count - 1 'Read the practice number and status from TblPracExclude Dim Prac_Req As New System.Data.SqlClient.SqlCommand(("Select prac_no, prac_enabled From dbo.TblPracExclude"), 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_no = DgvPracExcl.Rows(irow).Cells(0).Value Then If prac_enabled = DgvPracExcl.Rows(irow).Cells(3).Value Then MsgBox("No Practice need Update", MsgBoxStyle.Information, "VeriSIS") strFlag = "Ignore" Exit For Else MsgBox("Practice need Update", MsgBoxStyle.Information, "VeriSIS") strFlag = "Update" Exit For End If End If Next irow If strFlag = "Insert" Then Call PracticeInsert() ElseIf strFlag = "Update" Then Call UpdatePracEnabled() End If End SubCode:Private Sub UpdatePracEnabled() Dim conn As SqlConnection = GetDbConnection() Dim query As String Dim cmd As New SqlCommand Dim irow As Integer Try query = "UPDATE dbo.TblPracExclude SET prac_enabled ='" & _ DgvPracExcl.Rows(irow).Cells(3).Value & "' where Prac_No='" & _ DgvPracExcl.Rows(irow).Cells(0).Value & "'" cmd = New SqlCommand(query, conn) cmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS") End Try End SubInstead - I keep receiving the message box;Code:Private Sub PracticeInsert() Dim conn As SqlConnection = GetDbConnection() Dim query As String Dim cmd As New SqlCommand Dim irow As Integer Try query = "INSERT INTO dbo.TblPracExclude (prac_no, prac_name, prac_status, prac_enabled) VALUES (" & _ DgvPracExcl.Rows(irow).Cells(0).Value & ", '" & _ Replace(DgvPracExcl.Rows(irow).Cells(1).Value, "'", "''") & "', '" & _ DgvPracExcl.Rows(irow).Cells(2).Value & "', '" & _ DgvPracExcl.Rows(irow).Cells(3).Value & "')" cmd = New SqlCommand(query, conn) cmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "VeriSIS") End Try End Sub
No Practice need Update
Please could you help me out..




Reply With Quote