gucksch du :
Damit befüllst du eine listview mit dem SQL-blabla, ist praktisch exakt das gleiche wie mit dem oledb, einfach
den präfix sql in oledb abändern...
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:
| Procedure GetDR (var dr:SQLdatareader;SQL:String;var conn : SQLconnection); var cmd : SQLCommand; begin conn := SQLConnection.create('Server=icecube;Initial Catalog=Northwind;Integrated Security=true'); try cmd := SQLCommand.Create(SQL,conn); conn.open(); dr :=cmd.ExecuteReader (); except on ex: Exception do messagebox.show (ex.message,'Fehler bei Verbindungsaufbau !'); end; end;
Procedure LoadListView (lView : ListView;SQL :String); var item1: ListViewItem; SubItem: ListViewItem.ListViewSubItem ; a : integer; lvwCol : ColumnHeader; dr : SQLDatareader; cn : SQLConnection; begin LView.Clear; LView.View := View.Details; LView.FullRowSelect := True;
getDR (dr,SQL,cn);
if dr.read = True then begin with LView.Columns do begin for a := 0 to dr.FieldCount -1 do begin lvwCol := ColumnHeader.Create; lvwCol.Text := dr.GetName(a).ToString; Add (lvwCol); end; end; end; getDR (dr,SQL,cn);
while dr.read do begin item1 := ListViewItem.Create(dr.GetValue(0).toString.trim, 0); for a := 1 to dr.FieldCount -1 do begin SubItem := item1.SubItems.Add(dr.GetValue(a).toString.trim); end; LView.Items.Add(item1); end; for a := 0 to LView.Columns.Count -1 do begin try LView.Columns[a].Width := -2; except end; end; dr.close; cn.close; end;
procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs); Begin LoadListView (ListView1,'Select * from Shippers'); end; |
kannste übrigens ab oktober in meinem buch nachlesen...
den server solltest du natürlich ändern und die authentifizierungsmethode:
conn := SQLConnection.create('Server=
icecube;Initial Catalog=Northwind;Integrated Security=
true');
um sätze zu ändern nimmst du sowas:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
| Function ExecuteSQL (SQL:String):Integer; var cmd : SQLCommand; cn : SQLConnection; begin cn := SQLConnection.create(connSTR); cn.open(); Result := 0; try cmd := SQLCommand.Create (); cmd.CommandText := SQL; cmd.Connection :=cn; Result := cmd.ExecuteNonQuery(); except on ex: Exception do messagebox.show (ex.message+chr(13)+chr(10)+SQL,'Fehler bei Execute !'); end; cn.close (); cmd.Free ;
end; |
da kannst du nun einfach einen sqlbefehl übergeben:
Delphi-Quelltext
1:
| ExecuteSQL ('update table set x=y where id=1'); |
zurückliefern tut dir die funktion die anzahl der geänderten...
hope it helps