谁有用ADO写的数据库程序的源码啊! (88分)

  • 主题发起人 主题发起人 幸福鸟
  • 开始时间 开始时间

幸福鸟

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有用ADO写的数据库程序的源码啊!现在正在学ADO,不知从何学起,想看看高手是怎样
利用ADO的,给我发到邮箱,必有分相送!xingfuniao2001@163.com
 
我也想要呀,不知如何能过ADO来访问ORACLE数据库。
 
看看李维的《DELPHI高级程序设计——ADO......》
 
首先要搞清楚ado对象模型,
对什么数据库区别都不是很大.
至于例子,
delphi自带地demo里面有个详细地例子
 
to dotboy :访问ORACLE数据库用delphi6中的dbexpress怎么样?
 
访问MSSQL的要不要?
 
我要,谢谢!
wellc@cmmail.com
 
手里刚做完一个,用的是Access。
方法大致相同
 
前几日用了ADO,不知以下代码对你有没有用
unit TreeFrmUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, ComCtrls, ImgList, ToolWin, ExtCtrls, DB, ADODB,
Menus, ShellCtrls, StdCtrls;

type
TTreeFrm = class(TForm)
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
ToolButton10: TToolButton;
ToolButton11: TToolButton;
PageControl1: TPageControl;
StatusBar1: TStatusBar;
TabSheet1: TTabSheet;
PageControl2: TPageControl;
TabSheet2: TTabSheet;
TreeView1: TTreeView;
DBGrid1: TDBGrid;
Timer1: TTimer;
ADO: TADOConnection;
ADS: TADODataSet;
ADSTree: TADODataSet;
DataSource1: TDataSource;
ASP: TADOStoredProc;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
Panel1: TPanel;
ToolButton12: TToolButton;
ShellTreeView1: TShellTreeView;
ShellComboBox1: TShellComboBox;
Panel2: TPanel;
ShellListView1: TShellListView;
PopupMenu2: TPopupMenu;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
ImageList1: TImageList;
PopupMenu3: TPopupMenu;
N8: TMenuItem;
N9: TMenuItem;
procedure ToolButton11Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
function GetFieldList: TStringList;
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ADSAfterScroll(DataSet: TDataSet);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure DBGrid1TitleClick(Column: TColumn);
procedure ToolButton3Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
procedure PageControl2Change(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure N6Click(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure TreeView1Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure N9Click(Sender: TObject);
private
{ Private declarations }
Procedure GetTree_Data;
public
{ Public declarations }
end;

var
TreeFrm: TTreeFrm;
FieldList:TstringList;
implementation

uses umyfunction, Unit1, Unit2, SeachUnit, Unit3, Unit4, Unit5;

{$R *.dfm}

procedure TTreeFrm.ToolButton11Click(Sender: TObject);
begin
close;
end;

procedure TTreeFrm.ToolButton1Click(Sender: TObject);
begin
with PageControl1 do
Visible:=Not Visible;
if Pagecontrol1.Visible then
ToolButton1.Caption:='隐藏'
else
ToolButton1.Caption:='显示'
end;
procedure TTreeFrm.FormShow(Sender: TObject);
begin
WinFrm:=TWinFrm.create(application);
WinFrm.show;
WinFrm.update;
repeat
application.ProcessMessages;
Until WinFrm.closequery;
WinFrm.Hide;
WinFrm.Free;
StatusBar1.Panels[5].Text:=FormatDateTime('hh:mm:ss',now);
Hint:=Formatdatetime('yyyy"年"mm"月"dd"日"',now);
GetTree_Data;
end;

procedure TTreeFrm.Timer1Timer(Sender: TObject);
begin
StatusBar1.Panels[5].Text:=FormatDateTime('hh:mm:ss',now);
Statusbar1.Panels[7].Text:=formatdatetime('dddd',now);
Hint:=Formatdatetime('yyyy"年"mm"月"dd"日"',now);
end;

function TTreeFrm.GetFieldList: TStringList;
begin
FieldList.clear;
FieldList.add(ADSTree.fieldbyname('class').asstring);
FieldList.add(ADSTree.fieldbyname('zy').asstring);
Result := FieldList;
end;

procedure TTreeFrm.GetTree_Data;
begin
FieldList := TStringList.create;
TreeView1.items.BeginUpdate;
ADSTree.Close;
ADSTree.CommandText :='Select class,zy,Expr2 from student_View ';
ADSTree.OPEN;
//装载树形目录
TreeView1.Items.Clear ;
ADSTree.first;
while not ADSTree.eof do
begin
TreeAddItem(TreeView1, GetFieldList, ADSTree.getBookmark, false);
ADSTree.next;
end;
TreeView1.Alphasort; //重新排序
TreeView1.items.Endupdate;
end;

procedure TTreeFrm.ToolButton2Click(Sender: TObject);
begin
NationINFrm:=TNationINFrm.create(application);
NationINFrm.status.Caption:='资料增加';
NationINFrm.showmodal;
GetTree_Data;
end;

procedure TTreeFrm.ToolButton4Click(Sender: TObject);
begin
NationINFrm:=TNationINFrm.create(application);
NationINFrm.E1.Text:=trim(ADS.fieldbyname('Expr1').asstring);
NationINFrm.E2.Text:=trim(ADS.fieldbyname('Expr2').asstring);
NationINFrm.E3.Text:=trim(ADS.fieldbyname('Chinese').asstring);
NationINFrm.E4.Text:=trim(ADS.fieldbyname('sx').asstring);
NationINFrm.E5.Text:=trim(ADS.fieldbyname('English').asstring);
NationINFrm.E6.Text:=trim(ADS.fieldbyname('zz').asstring);
NationINFrm.E7.Text:=trim(ADS.fieldbyname('zy').asstring);
NationINFrm.E8.Text:=trim(ADS.fieldbyname('class').asstring);
NationINFrm.status.Caption:='资料修改';
NationINFrm.showmodal;
ADS.Close;
ADS.Open;
GetTree_Data;
end;

procedure TTreeFrm.ADSAfterScroll(DataSet: TDataSet);
begin
Statusbar1.Panels[3].Text:=Inttostr(ADS.RecNo)+'/'+Inttostr(ADS.RecordCount); //显示和统计当前记录
end;

procedure TTreeFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=Cafree;
end;

procedure TTreeFrm.FormDestroy(Sender: TObject);
begin
TreeFrm:=Nil;
end;

procedure TTreeFrm.DBGrid1TitleClick(Column: TColumn);
var //排序
DataSet:TDataSet;
begin
DataSet:=Column.Field.DataSet;
if DataSet is TCustomADODataSet then
with TCustomADODataSet(DataSet) do
begin
if (POS(Column.Field.FieldName,Sort)=1)
and (POS(' DESC',Sort)=0) then
Sort:=Column.Field.FieldName+' DESC'
else
Sort:=Column.Field.FieldName+' ASC';
end;
end;

procedure TTreeFrm.ToolButton3Click(Sender: TObject);
var
Rec:Integer;
begin
if ADS.IsEmpty then Exit;
if Application.MessageBox('确认删除该记录吗?','提示...',Mb_YesNo)=IDNo then Exit;
Rec:=ADS.RecNo;
ASP.Close ;
ASP.ProcedureName:='Tstudent_Delete';
ASP.Parameters.Clear ;
ASP.Parameters.CreateParameter('pa0',ftstring,pdinput,7,trim(ADS.Fieldbyname('Expr1').AsString));
ASP.ExecProc ;
ADS.Close ; //刷新数据库
ADS.Open ;
ADS.MoveBy(Rec-1);
GetTree_Data;
end;

procedure TTreeFrm.N1Click(Sender: TObject);
begin
ADS.Close;
ADS.CommandText:='select * from student_view'; //全部记录显示
ADS.Open;
end;

procedure TTreeFrm.PageControl1Change(Sender: TObject);
begin
if PageControl1.ActivePage=TabSheet1 then
begin
PageControl2.ActivePage:=Tabsheet2;
ToolButton12.Enabled:=false;
end;
if PageControl1.ActivePage=TabSheet3 then
begin
PageControl2.ActivePage:=TabSheet4;
ToolButton12.Enabled:=True;
end;
end;

procedure TTreeFrm.PageControl2Change(Sender: TObject);
begin
if PageControl2.ActivePage=TabSheet2 then
begin
PageControl1.ActivePage:=Tabsheet1;
ToolButton12.Enabled:=false;
end;
if PageControl2.ActivePage=TabSheet4 then
begin
PageControl1.ActivePage:=TabSheet3;
ToolButton12.Enabled:=True;
end;
end;

procedure TTreeFrm.N4Click(Sender: TObject);
begin
ShellListView1.ViewStyle:=Vsicon;
end;

procedure TTreeFrm.N5Click(Sender: TObject);
begin
ShellListView1.ViewStyle:=vsSmallIcon;
end;

procedure TTreeFrm.N6Click(Sender: TObject);
begin
ShellListView1.ViewStyle:=vsReport;
end;

procedure TTreeFrm.N7Click(Sender: TObject);
begin
ShellListView1.ViewStyle:=vsList;
end;

procedure TTreeFrm.ToolButton7Click(Sender: TObject);
begin
if ADS.IsEmpty then
begin
Application.MessageBox('无数据可保存,重试!',pchar(caption),mb_ok+mb_iconquestion);
Exit;
end;
ExportExcelForm:=TExportExcelForm.create(application);
//ExportExcelForm.saveExcel(TreeFrm.ADS,TreeFrm);
ExportexcelForm.showmodal;
end;

procedure TTreeFrm.TreeView1Click(Sender: TObject);
var
str1,str2,str3:string;
begin
ADS.Close;
if TreeView1.Items.Count=0 then exit;
if TreeView1.Selected.Level=0 then
begin
str1:=TreeView1.Selected.Text;
str2:='';
str3:='';
ADS.CommandText :='select * from student_View where class=:ok ' ;
ADS.Parameters.ParamByName('ok').Value:=str1;
end;
if TreeView1.Selected.Level=1 then
begin
str1:=TreeView1.Selected.Parent.Text;
str2:=TreeView1.Selected.Text;
str3:='';
ADS.CommandText :='select * from student_View where class=:ok and zy=:ok1' ;
ADS.Parameters.ParamByName('ok').Value:=str1;
ADS.Parameters.ParamByName('ok1').Value:=str2;
end;
ADS.Open;
end;

procedure TTreeFrm.N3Click(Sender: TObject);
var
i:integer;
begin
SearchFrm:=TSearchFrm.Create(Application);
searchFrm.ComboBox1.Items.Clear;
searchFrm.ComboBox2.Items.Clear;
For i:=0 to DBGrid1.Columns.Count-1 do
searchFrm.Combobox2.Items.Add(DBGrid1.Columns.Title.Caption);
For i:=0 to ADS.FieldCount-1 do
searchFrm.Combobox1.Items.Add(ADS.Fields.FieldName);
SearchFrm.ShowModal;
end;

procedure TTreeFrm.N8Click(Sender: TObject);
begin
PrintFrm1:=TPrintFrm1.Create(application);
PrintFrm1.QuickRep1.Preview;
end;

procedure TTreeFrm.N9Click(Sender: TObject);
begin
PrintFrm2:=TPrintFrm2.Create(application);
PrintFrm2.QuickRep1.Preview;
end;

end.
 
我想要一個用ADO設計的一對多的窗体的例子
(最好是批量提交的方式的),不知哪位大大蝦有!

zengys2001@163.com[:)]
 
谁还要?
 
to seeme0526
谢谢你给我发的代码,但我从网上下载之后怎么解不开啊!麻烦您在发一便好吗!
 
我也要 tdsoft@21cn.com
 
多人接受答案了。
 
后退
顶部