Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert contents of stringarray into Db record?

Status
Not open for further replies.

corsair2

IS-IT--Management
Feb 21, 2001
55
GB
Hi!

anyone know how to insert the contents of a string array into a Db records' fields?
For example I've tried

CDS1.InsertRecord([StringArray]);

which throws up the error "Invalid value for Field 'Field1'".

(NB; all the fields in the Db Table I'm trying to write to are string-types.)

I've tried writing the string array to a variant array prior to trying to insert the data into the record but during the attempted insertion this simply throws up another problem with "Invalid variant type conversion".

I know 'InsertRecord' expects an 'array of const' but frankly the job has been so difficult just to get to this stage that it never occurred to me that actually getting the info. into a table would be a problem!

Anyone out there who can help?

 
With an array you have to declare each part of the array.
For example

var
ArrayString[1..4] : Array of String;
begin
ArrayString[1] := Edit1.Text;
ArrayString[2] := Edit2.Text;
ArrayString[3] := Edit3.Text;
ArrayString[4] := Edit4.Text;
end;

You could declare a standard string and collate the array as follows.

var
S : String;
begin
S := ArrayString[1] + ArrayString[2] + ArrayString[3] + ArrayString[4];

{Insert new string S into table record}
end;
 
Instead of using an array of string, maybe you could use a TStringList:
Code:
var myStrings: TStringList;
begin
    myStrings := TStringList.Create;

    // then load up your values, with myStrings.Add() or by setting myStrings.CommaText

    myTable.InsertRecord(myStrings.Strings);

end;
I haven't actually tried this; so let me know if it works. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top