![]() |
Datenbank: Access • Version: 2000 • Zugriff über: Adoquery
DBgrid in csv - Problem
Moin!
Ich hab da ein Problem. Ich soll einzelne Spalten verschiedener DB-Tabellen in eine csv schreiben um diese dann anschließend via php in mySQL einzufügen. Ich bin hier eigentlich schon fündig geworden - einziges Problem: die daten werden wie folgt gespeichert: 2,"LS Stochastik",1 6,"LS Analysis",1 8,Mathematik,1 10,Mathematik,1 sollte aber eigentlich so aussehen "2","LS Stochastik","1" "6","LS Analysis","1" "8","Mathematik","1" "10","Mathematik","1" Hier mein Quelltext:
Delphi-Quellcode:
Ich danke schonmal im voraus!
function Tmainform.buch:boolean;
var s, csv: TStrings; i: integer; begin csv := TStringList.Create; s := TStringList.Create; with ADOQuery1 do begin begin ADOQuery1.Close; DataSource1.DataSet := ADOQuery1; ADOQuery1.SQL.Text:='select bookid,title,mediumid from bookstab'; ADOQuery1.Open; while not Eof do begin s.Clear; for i := 0 to Pred(FieldCount) do s.Add(Fields[i].AsString); csv.add(s.CommaText); Next; end; Close; end; s.Free; csv.SaveToFile(ExtractFilePath(Application.Exename)+'\dbtxt\buch.txt'); csv.Free; result:=true; end; end; Mfg Deralex |
Re: DBgrid in csv - Problem
Vom Jediprojekt gibt es eine Komponente CSVDataSet.
|
Re: DBgrid in csv - Problem
Ist das der einzige Weg? ist es nicht möglich mit ein wenig "feintuning" an der Variante die ich bisher gewählt habe das Problem zu lösen?
Jedi müsste ich auch erst installieren. Gruß Alex PS: Beispiel-Code wäre echt hilfreich....;-) |
Re: DBgrid in csv - Problem
Herzlich willkommen in der Delphi-PRAXiS, Alex.
Hier ein Nachrüst-Kit für dich:
Delphi-Quellcode:
Freundliche Grüße vom marabu
function DelimitedText(s: TStrings; const cDelimiter: Char = ',';
const cQuote: Char = '"'): String; var i, iPos, iLength: Integer; line: String; begin if s.Count = 0 then Result := '' else // calculate resulting length begin // account for delimiters iLength := Pred(s.Count); for i := 0 to Pred(s.Count) do begin line := s[i]; // account for outer quotes Inc(iLength, Length(line) + 2); for iPos := 1 to Length(line) do // account for escape chars Inc(iLength, Ord(line[iPos] = cQuote)); end; // dimension result SetLength(Result, iLength); iPos := 1; for i := 0 to Pred(s.Count) do begin if i > 0 then begin Result[iPos] := cDelimiter; Inc(iPos); end; line := AnsiQuotedStr(s[i], cQuote); Move(line[1], Result[iPos], Length(line)); Inc(iPos, Length(line)); end; end; end; |
Re: DBgrid in csv - Problem
Danke! Prog läuft jetzt so wie's soll! Dickes Danke!
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz