Board index » delphi » Could not convert variant of type (null) into type (String)

Could not convert variant of type (null) into type (String)

Dear Sir~
i get a error message :
Project test.exe raised exception class EVariantTypeCastError with
Message'Could not convert variant of type (null) into type (String)'

This is where I get my error (Test application, very basic):

Add three components to TForm1:

Conn:
   -TAdoConnection
   -Connecting via ODBC to an MS Access database using a connection
string

ADOTable1:
   -TADOTable
   -Uses Conn above as its connection
   -Table name is set to the only user table in the Access database
   -By the way, the table has only one field - an integer field

Button1
   -TButton
   -OnClick handler shown in code below.
==================================================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
  Dialogs, StdCtrls, DB, ADODB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    conn: TADOConnection;
    ADOTable1: TADOTable;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 conn.Connected := true;
 adoTable1.Active := true; // Error is generated here
end;

end.

===============================
Additional information:
* Delphi Enterprise ver 6 with update pack 2 ("D6_upd2_ent.exe") installed.
* Tried with MDAC V 2.6 and MDAC V2.7
* Running on Windows 2000 OS
* Have the full Microsoft Office 2000 package installed too.
* Microsoft SQL Server 2000

 

Re:Could not convert variant of type (null) into type (String)


Quote
>Conn:
>   -TAdoConnection
>   -Connecting via ODBC to an MS Access database using a connection
>string

I believe this is an error you only get running out of the IDE.  Either switch
to Jet 4.0 Ole DB driver where you won't get the error or continue using the
ODBC driver (which I can't imagine any good reason to be doing) and ignore this
error.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads