All, I wonder if you can help me, I have the following code that is returning unexpected results and I have no idea why:
The DBcommand commandtext results are:
"Select Max(CSDNo) as MaxofCSDNo from CSDs WHERE CSDNo Like Cstr(7)&'*'"
which I have tested in the back end database (Access) and it works with a resulting record of 7002.
However the value of getNewCSDNoReader.GetValue(0) is DBNull.Value and I just don't get why?
Any ideas?
Thanks in advance.
Code:
Dim searchYear As String
If InStr(3, wholeYear) = "0" Then
searchYear = Right(wholeYear, 1)
Else
searchYear = Right(wholeYear, 2)
End If
'now we need to get the last number for the search year and increment by 1
DBCommand.CommandText = "Select Max(CSDNo) as MaxofCSDNo from CSDs WHERE CSDNo Like Cstr(" + searchYear + ")&'*'"
Connection.Open()
Dim getNewCSDNoReader As OleDb.OleDbDataReader = DBCommand.ExecuteReader(CommandBehavior.CloseConnection)
While getNewCSDNoReader.Read
Dim getNewNo As String
If Not getNewCSDNoReader.GetValue(0) Is DBNull.Value Then
getNewNo = CStr(getNewCSDNoReader.GetValue(0) + 1)
Else
getNewNo = searchYear & "001"
End If
End While
Connection.Close()
The DBcommand commandtext results are:
"Select Max(CSDNo) as MaxofCSDNo from CSDs WHERE CSDNo Like Cstr(7)&'*'"
which I have tested in the back end database (Access) and it works with a resulting record of 7002.
However the value of getNewCSDNoReader.GetValue(0) is DBNull.Value and I just don't get why?
Any ideas?
Thanks in advance.