Jump to content

'Could not convert variant of type (String) into type (Double)'

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Ilikestring

Ilikestring

    Newbie

  • Members
  • PipPip
  • 17 posts
      AllocateColumn := 0;
      For Count := 1 to (ADOTable1.FieldCount - 1) do
        Begin
          If ADOTable1['Student' + IntToStr(Count)] <> 0 Then
            Begin
              AllocateColumn := AllocateColumn + 1;
              ADOQuery1.SQL.Clear;
              ADOQuery1.SQL.Add('UPDATE Timetable');
              ADOQuery1.SQL.Add('SET TimeSlot' + IntToStr(AllocateColumn) + ' = ' + [B]ADOTable1['Student' + IntToStr(Count)])[/B];   
              ADOQuery1.SQL.Add('WHERE Teacher = ' + SortedNumofAppsPerTeach[Temp, 1] + ';');
              ADOQuery1.ExecSQL;
            end;

The problem part of the code is in bold. As you can see, I have used exactly the same code for the IF statement above and it works fine.
Any ideas? Google gives me nothing.

If it helps, Count, Temp and AllocateColumn are integers.

Problem has been fixed. Thank you

Edited by Ilikestring, 26 March 2010 - 06:41 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It looks like you are attempting to set TimeSlotX, a field of type double, to StudentX, a field that is NOT compatible with double. What's your data?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Ilikestring

Ilikestring

    Newbie

  • Members
  • PipPip
  • 17 posts
The error occurs before the SQL executes. It occurs as soon as it processes the line
ADOQuery1.SQL.Add('SET TimeSlot' + IntToStr(AllocateColumn) + ' = ' + ADOTable1['Student' + IntToStr(Count)]);
So I don't think that is the problem. I have also narrowed the problem down to the ADOTable1['Student' + IntToStr(Count)]). That is definitely the issue.
But, StudentX is a four-digit number. Count, Temp and AllocateColumn could be anything around 1 - 50.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You probably need this:
ADOQuery1.SQL.Add('SET TimeSlot' + IntToStr(AllocateColumn) + ' = ' + inttostr(ADOTable1['Student' + IntToStr(Count)]));

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog