Hi guys,
I am using .net cf 2.0.
I am trying to get the maximum value from a column in a table in my database and then call a function using the value returned.
Here's the code i have:
VB Code:
sqlCmd = Database.sqlConn.CreateCommand With sqlCmd .CommandText = "SELECT MAX(seqOrder) FROM questionnaire_results WHERE visitID = @visitID AND qID = @qID" .Parameters.Add(New SqlCeParameter("@visitID", GetCurrentVisit())) .Parameters.Add(New SqlCeParameter("@qID", qID)) maxSeqOrder = .ExecuteScalar.ToString If IsDBNull(maxSeqOrder) OrElse IsNothing(maxSeqOrder) Then maxSeqOrder = 0 End If Select Case maxSeqOrder Case "0" DisplayQuestion(0) Case Else DisplayQuestion((CInt(maxSeqOrder) / 5) - 1) End Select End With
Now everytime i run this code i keep getting an invalidcast exception. maxSeqOrder is declared (currently) as a string and DisplayQuestion needs to be passed an integer. I have tried using maxseqorder as an integer but i get the same exception. I have put debug lines in and found that the exception is thrown at the line
when maxseqorder is a string and a integer. I have tried to get help from a colleaugue but neither of us can see why the exception is being thrown.VB Code:
maxSeqOrder = .ExecuteScalar.ToString
Can anybody else see where the problem is coming from?
Thanks in advance for any help
![]()




Reply With Quote