Autor Beitrag
Jangojack Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

win xp
Delphi 2005 personal,Delphi 7 Enterprise
BeitragVerfasst: Mi 06.09.06 11:27 
Titel: 0_o?
Noch jemand ne idee???

user defined image
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Mi 06.09.06 13:56 
Hallo,
wo genau liegt denn dein Problem? Ich hab hier bei mir eine Tabelle in einem Stringgrid abgebildet, aber bei deinem Code, bzw. beim Tutorial steig ich nicht durch. Ich hab sonst auch immer nur mit php und phpmyadmin gearbeitet. Ich versuch mal ein Testprogramm zu erstellen.

Edit: Vielleicht hilft es dir in irgend einer Form. :)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
procedure TForm1.Button3Click(Sender: TObject);
var
  lResult: PMYSQL_RES;
  lRow: PMYSQL_ROW;
  i: Integer;
begin
  mysql_real_query(FMySQL.FCon, PChar((*'SELECT * FROM gaestebuch;'*) Edit4.Text), length(Edit4.Text));
  lResult := mysql_store_result(FMySQL.FCon);

  ShowMessage('FieldCount: ' + IntToStr(lResult.field_count));
  for i := 0 to lResult.field_count - 1 do
    ShowMessage(lResult.fields[i].name);

  with StringGrid1 do
    begin
      RowCount := mysql_num_rows(lResult) + 1;
      ColCount := 4;
      Cells[1, 0] := 'ID';
      Cells[2, 0] := 'Name';

      for i := 0 to mysql_num_rows(lResult) - 1 do
        begin
          lRow := mysql_fetch_row(lResult);
          Cells[1, i + 1] := lRow[0];
          Cells[2, i + 1] := lRow[1];
        end;
    end;


(*  for i := 0 to mysql_num_rows(lResult) - 1 do
    begin
      lRow := mysql_fetch_row(lResult);
      ListBox1.Items.Add('ID: ' + lRow[0] + ' Titel: ' + lRow[3]);
    end;  *)


  mysql_free_result(lResult);
end;


MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Jangojack Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

win xp
Delphi 2005 personal,Delphi 7 Enterprise
BeitragVerfasst: Fr 08.09.06 09:33 
Titel: hi nochmal
Ich habe mit diesem tutorial www.dsdt.info/tutori.../mysqldirect/?page=2
ein prog. geschrieben was alles "nötige" kann

nur die ansicht im stringgrid funktioniert nicht - kann mir da jemand helfen

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,umysqlvio, uMysqlCT, uMysqlClient, uMysqlHelpers, StdCtrls, Grids,
  ComCtrls, Menus;

  {$I mysqlinc.inc}

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    StatusBar1: TStatusBar;
    Navigation: TGroupBox;
    connect_btn: TButton;
    disconnect_btn: TButton;
    ping_btn: TButton;
    recon_btn: TButton;
    Database: TGroupBox;
    choosedb_btn: TButton;
    createdb_btn: TButton;
    delete_btn: TButton;
    changeuser_btn: TButton;
    mysqlstats_btn: TButton;
    close_btn: TButton;
    qry_btn: TButton;
    quest_btn: TButton;
    createtable_btn: TButton;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    close1: TMenuItem;
    procedure connect_btnClick(Sender: TObject);
    procedure disconnect_btnClick(Sender: TObject);
    procedure ping_btnClick(Sender: TObject);
    procedure recon_btnClick(Sender: TObject);
    procedure choosedb_btnClick(Sender: TObject);
    procedure createdb_btnClick(Sender: TObject);
    procedure changeuser_btnClick(Sender: TObject);
    procedure mysqlstats_btnClick(Sender: TObject);
    procedure formcreate(Sender: TObject);
    procedure formdestroy(Sender: TObject);
    procedure delete_btnClick(Sender: TObject);
    procedure TableContent;
    procedure TableStructure;
    procedure close_btnClick(Sender: TObject);
    procedure qry_btnClick(Sender: TObject);
    procedure close1Click(Sender: TObject);
    procedure createtable_btnClick(Sender: TObject);


  private
  FMysql: TMysqlClient;
  FResult: TMysqlResult;
    { Private-Deklarationen }
  public

    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//#############connect button################

procedure TForm1.connect_btnClick(Sender: TObject);
begin
  // Eigenschaften setzen

  FMysql.Host := 'localhost';
  FMysql.port := 3306;
  FMysql.user :='';
  FMysql.password := '';
  FMysql.UnixSocket := '';
  FMysql.Db := 'test'; // Datenbank auf dem Server
  FMysql.UseNamedPipe := false;
  FMysql.UseSSL := false;
  FMysql.Compress := true;
  FMysql.TrySockets := false;

    if FMysql.Connect then begin
      StatusBar1.Panels[0].Text := 'Status : Connected     ';
  end
    else begin
    StatusBar1.Panels[0].Text := 'Status : Not Connected     ';
  end;
end;

//################disconnect button##############

procedure TForm1.disconnect_btnClick(Sender: TObject);
begin
 if FMysql.Connected then
    FMysql.close
  else
   StatusBar1.Panels[0].Text := 'Status : Not Connected     ';
end;


//##################ping button###################

procedure TForm1.ping_btnClick(Sender: TObject);
begin
    if FMysql.ping then begin
    StatusBar1.Panels[0].Text := 'Status : Ping ok     ';
  end
  else begin
    StatusBar1.Panels[0].Text := 'Status : Ping Fehlgeschlagen   ';
  end;
end;


//##################reconnect button#############

procedure TForm1.recon_btnClick(Sender: TObject);
begin
 if FMysql.reconnect then begin
   StatusBar1.Panels[0].Text := 'Status : Reconnected     ';
   end
 else
   StatusBar1.Panels[0].Text := 'Status : Reconnected Fehlgeschlagen     ';
end;



//##################choose db button##############

procedure TForm1.choosedb_btnClick(Sender: TObject);
var db: string;
begin
  db := InputBox('Geben Sie einen Datenbank-Namen ein',
  'Welche DB auswählen','');
  if FMysql.select_db(db) then begin
    statusbar1.Panels[0].Text:= 'Select db: OK         ';
   end
  else
    statusbar1.panels[0].text := 'Select db fehlgeschlagen ';
end;


//####################create db button##############

procedure TForm1.createdb_btnClick(Sender: TObject);
var db: string;

begin
  db := InputBox('Geben Sie einen Datenbank-Namen ein',
  'Welche DB erzeugt werden soll','');
  if FMysql.create_db(db) then begin
    statusbar1.panels[0].text :='Create db: OK        ';
   end
  else
    statusbar1.panels[0].text :='Create db fehlgeschlagen        ';
end;


//####################change user button#############

procedure TForm1.changeuser_btnClick(Sender: TObject);

var user, pass, db: string;
begin
  user := InputBox('Geben Sie einen User-Namen ein','User-Name','');
  pass := InputBox('Geben Sie ein Passwort ein','Passwort','');
  db := InputBox('Geben Sie einen DB-Namen ein',
  'Welche DB ist auszuwählen','');
  if FMysql.change_user(user, pass, db) then begin
    statusbar1.panels[0].text :='Userwechsel: Erfolgreich      ';
    end
  else
    statusbar1.panels[0].text :='Userwechsel fehlgeschlagen              ';
end;



//###################mysqlstats button##############

procedure TForm1.mysqlstats_btnClick(Sender: TObject);
begin
ShowMessage('Stat: '+FMysql.stat);
statusbar1.panels[0].text :=('Stat: '+FMysql.stat);

end;


//##################close button##################

procedure TForm1.close_btnClick(Sender: TObject);
begin
FreeAndNil(FResult);
application.Terminate;
end;


//##################delete button##############

procedure TForm1.delete_btnClick(Sender: TObject);

var db: string;
begin
  db := InputBox('Geben Sie einen Datenbanknamen ein',
  'Welche DB ist zu löschen','');
  if FMysql.drop_db(db) then begin
    //ShowMessage('Drop db: OK')
    statusbar1.panels[0].text :='Drop db: Erfolgreich     ';
   end
  else
    statusbar1.panels[0].text :='Drop db fehlgeschlagen:         ';
end;


//##################qry button####################

procedure TForm1.qry_btnClick(Sender: TObject);

var q: string;
    ex: boolean;
begin
  if assigned(FResult) then begin
    if FMysql.Status<>MYSQL_STATUS_READY then
      ShowMessage('Ein Ergebnis wurde unvollständig gelesen!');
      statusbar1.panels[0].text :='Ein Ergebnis wurde unvollständig gelesen';
      FreeAndNil(FResult);
  end;
  q := InputBox('Geben Sie eine Abfrage ein',
  'Welche Abfrage durchgeführt werden soll','');
  FResult := FMysql.query(q, true, ex);
  if assigned(FResult) then begin
    //ShowMessage('Query: OK - Ergebnis gespeichert')
    statusbar1.panels[0].text :='Query: Ergebnis gespeichert';
  end
  else
    if ex then begin
      //ShowMessage('Query: OK - ausgeführt')
      statusbar1.panels[0].text :='Query: Erfolgreich ausgeführt';
     end
    else
      //ShowMessage('Query fehlgeschlagen: '+FMysql.LastError);
    statusbar1.panels[0].text :=('Query fehlgeschlagen: '+FMysql.LastError);
end;


//##################ON FORM CREATE################

procedure TForm1.formcreate(Sender: TObject);
begin
  FMysql := TMysqlClient.create;
end;

//##################ON FORM DESTROY##############

procedure TForm1.formdestroy(Sender: TObject);
begin
  FMysql.Free;
  if FResult<>nil then
    FResult.free;
end;


//#######################TABLE###################

procedure TForm1.TableStructure;
var  i: integer;
    af: TMysql_FieldDef;

begin
  if assigned(FResult) then begin
    StringGrid1.RowCount := FResult.FieldsCount+1;
    for i:=0 to FResult.FieldsCount-1 do begin
      af:=FResult.FieldDef(i)^;
      StringGrid1.Cells[0,i+1]:=af.Name;
      StringGrid1.Cells[1,i+1]:=af.Table;
      StringGrid1.Cells[2,i+1]:=IntToStr(af.Field_Type);
      StringGrid1.Cells[3,i+1]:=IntToStr(af.Length);
      StringGrid1.Cells[4,i+1]:=IntToStr(af.Max_Length);
      StringGrid1.Cells[5,i+1]:=IntToStr(af.Flags);
      StringGrid1.Cells[6,i+1]:=IntToStr(af.Decimals);
    end;
  end;
end;
procedure tform1.TableContent;
var i, j: integer;
    af: TMysql_FieldDef;
    cr: integer;
begin
  if assigned(FResult) then begin
    if FResult.ResultType=rtStored then begin
      cr := FResult.RecNo;
      StringGrid2.RowCount := FResult.RowsCount+1;
      StringGrid2.ColCount := FResult.FieldsCount+1;
      for i:=0 to FResult.FieldsCount-1 do begin
        af := FResult.FieldDef(i)^;
        StringGrid2.cells[i+1,0] := af.Name;
      end;
      FResult.First;
      for i:=0 to FResult.RowsCount-1 do begin
        if FResult.RecNo=cr then
          StringGrid2.Cells[0,i+1] := '*'
        else
          StringGrid2.Cells[0,i+1] := '';
        for j:=0 to FResult.FieldsCount-1 do
          StringGrid2.Cells[j+1,i+1] := FResult.FieldValue(j);
        FResult.Next;
      end;
      FResult.RecNo := cr;
    end
    else begin
      StringGrid2.RowCount := 2;
      StringGrid2.ColCount := FResult.FieldsCount+1;
      for i:=0 to FResult.FieldsCount-1 do begin
        af := FResult.FieldDef(i)^;
        StringGrid2.cells[i+1,0] := af.Name;
      end;
      for j:=0 to FResult.FieldsCount-1 do
        StringGrid2.Cells[j+1,1] := FResult.FieldValue(j);
    end;
  end;
end;

//#############################w00T o_0?###################


procedure TForm1.close1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.createtable_btnClick(Sender: TObject);
var tb: string;
    ex: boolean;
begin
  tb := InputBox('Geben Sie einen Tabellen-Namen ein',
  'Welche DB erzeugt werden soll','CREATE TABLE posts(id int, author int, date datetime, entry text)');
 FResult := FMysql.query(tb, true, ex);
  if assigned(FResult) then begin
    //ShowMessage('Query: OK - Ergebnis gespeichert')
    statusbar1.panels[0].text :='Query: Ergebnis gespeichert';
  end
end;
end.


heissen dunk im voraus

mfg johannes
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Fr 08.09.06 09:48 
Moin,
häng mal bitte dein Projekt (mit Sourcen) an, falls Möglich. So bin ich nicht gewillt erst alles bei mir einzurichten. :? Außerdem sage mal, was denn bei der Darstellung im SG nicht hinhaut. Gibt es Fehlermeldungen? ;) Je detailierte deine Aussage, je besser können wir dir helfen. ;)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Jangojack Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

win xp
Delphi 2005 personal,Delphi 7 Enterprise
BeitragVerfasst: Fr 08.09.06 09:58 
es kommt keine fehlermeldung o.ä.

es passiert einfach äeehhmm - gar nichts

wer helfen möchte und die source braucht bitte über pn anquatschen

thx m8tys

mfg johannes
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Fr 08.09.06 11:36 
An welcher Stelle rufst du denn "TableStructure;" auf?! Hau dir mal nen Button auf die Form und ruf das auf. ;)
So hab ich es gemacht:
- Über einen eigenen Button zur DB connected (deins ging net)
- Qry abgesetzt
- Button mit "TableStructure;" gedrückt 8)

MfG
freak

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Jangojack Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

win xp
Delphi 2005 personal,Delphi 7 Enterprise
BeitragVerfasst: Mo 11.09.06 13:58 
Titel: lol
ahhh ich musste nur einen mysql qry machen

"Select * from tabelle;"

kann auch nicht anders gehen

wo keine abfrage ist ist auch kein ergebnis

thx m8tys