Einzelnen Beitrag anzeigen

Matt

Registriert seit: 13. Nov 2003
Ort: Hamburg
212 Beiträge
 
#5

Re: Datenimport von zB .xls zu mysql

  Alt 4. Sep 2007, 17:45
Hallo Fred,

ich hab das so gelöst, das ich mir die Daten aus der XLS in ein Dataset lade, das in einem Gríd anzeige und das anschließend durchlaufe und Zeile für Zeile in ein Memo schreibe.

Delphi-Quellcode:
  
col := ds_im.DataSet.FieldCount;

cs:='CREATE TABLE 'Tabelle1'(`ID` int(11) NOT NULL auto_increment,';

for z := 0 to col-1 do begin
  cs := cs + '`' + ds_im.DataSet.Fields[z].FieldName + '` varchar(255),';
  next;
end;

  cs := cs + ' PRIMARY KEY (`ID`)) TYPE=MyISAM;';

  textablage.Lines.Add(cs);
  textablage.Lines.Add('');

  ds_im.DataSet.First;
  ad := ds_im.DataSet.RecordCount;
  
  //pb = statusbar
  pb.Visible := true;
  pb.Max := ad;
  pb.Position := 0;

while not ds_im.DataSet.Eof do begin
  pb.StepBy(1);
  cs:= 'Insert into 'Tabelle1' Values(' + quotedstr(inttostr(pb.position)) + ',';
  for z := 0 to col-1 do begin
  cs := cs + quotedstr(ds_im.DataSet.Fields[z].AsString) + ',';
  next;
end;

cs:= leftstr(cs,strlen(pchar(cs))-1) + ');';

memo.Lines.Add(cs);
ds_im.DataSet.next;
Wenn fertig verbinde dich mit dem MySQL Server führe den Script aus (aus memo).

Gruß Matt
  Mit Zitat antworten Zitat