dr223
August 19th, 2009, 09:55 AM
Hallo,
At run time my application gives an error of "Conversion from type "DBNull" to type "String" is not valid. In my form only one field - Add_info is an optional field which might be filled or not by the user.
Before, I had an error when an apostrophe was used so i updated the code as highlighted below. This in return removed the apostrophe error but generated an error whenever there is an empty additional field.
Any help please... Thanks
For irow = 0 To QryColSentDataGridView.Rows.Count - 1
If QryColSentDataGridView.Rows(irow).Cells(3).Value = True Then
Try
query = "UPDATE gprdsql.TblCollections SET system_time = '" & _
Labeldate.Text & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
query = "UPDATE gprdsql.TblCollections SET additional_info = '" & _
Replace(QryColSentDataGridView.Rows(irow).Cells(2).Value, "'", "''") & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
query = "UPDATE gprdsql.TblCollections SET stage = '" & _
"Sent" & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "GCPM")
End Try
End If
Next irow
At run time my application gives an error of "Conversion from type "DBNull" to type "String" is not valid. In my form only one field - Add_info is an optional field which might be filled or not by the user.
Before, I had an error when an apostrophe was used so i updated the code as highlighted below. This in return removed the apostrophe error but generated an error whenever there is an empty additional field.
Any help please... Thanks
For irow = 0 To QryColSentDataGridView.Rows.Count - 1
If QryColSentDataGridView.Rows(irow).Cells(3).Value = True Then
Try
query = "UPDATE gprdsql.TblCollections SET system_time = '" & _
Labeldate.Text & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
query = "UPDATE gprdsql.TblCollections SET additional_info = '" & _
Replace(QryColSentDataGridView.Rows(irow).Cells(2).Value, "'", "''") & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
query = "UPDATE gprdsql.TblCollections SET stage = '" & _
"Sent" & "' where prac_no ='" & _
QryColSentDataGridView.Rows(irow).Cells(0).Value & " ' and stage ='" & _
"Request" & " ' "
cmd = New SqlCommand(query, conn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "GCPM")
End Try
End If
Next irow