急,急,如何连接数据库 请举例说明:1:通过ODBC如何连接。2:通过BDE如何连接。谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BDE:procedure TBasDM.DataModuleCreate(Sender: TObject);begin LoginServer; //连接过程end;Procedure TBasDM.LoginServer;var tempIni: TIniFile; tmpServerFrm: TServerFrm; i:Integer; tmpList:TStringList; IsAliasName:Boolean;begin IsAliasName:=false; tmpList:= TStringList.Create; try Session.GetAliasNames(tmpList); for I := 0 to tmpList.Count - 1 do if tmpList[i]='CostingDB' then IsAliasName:=true; if not IsAliasName then Session.AddAlias('CostingDB','MSSQL',CostDB.Params); finally tmpList.Free; end; if CostDB.Connected then CostDB.Connected := False; pubLocaOption := [loCaseInsensitive, loPartialKey]; InitDBbasefile; //过程名 with CostDB.Params do begin Values['SERVER NAME'] := curServerName; Values['DATABASE NAME'] := curDBName; Values['USER NAME'] := 'sa'; Values['PASSWORD'] := ''; end; try CostDB.Open; except if Application.MessageBox('数据库连接失败,要重新设置吗?','系统', MB_ICONQUESTION+MB_YESNO)=ID_YES then begin tmpServerFrm:=TServerFrm.Create(Application); tmpServerFrm.ShowModal; if tmpServerFrm.ModalResult = mrOk then begin curServerName := tmpServerFrm.Edit1.Text; curDBName := tmpServerFrm.Edit2.Text; tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini'); tempIni.WriteString('SYSTEM', 'SERVER', curServerName); tempIni.WriteString('SYSTEM', 'DBNAME', curDBName); tmpServerFrm.Free; tempIni.Free; end; end else begin Application.Terminate; end; end;end;procedure TBasDM.InitDBbasefile;var tempIni: TIniFile; tmpServerFrm: TServerFrm;begin tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini'); curServerName := tempIni.ReadString('SYSTEM', 'SERVER', ''); curDBName := tempIni.ReadString('SYSTEM', 'DBNAME', ''); curAutoCADPath := tempIni.ReadString('WinExePath', 'AutoCADPath', ''); curWordPath := tempIni.ReadString('WinExePath', 'WordPath', ''); curExcelPath := tempIni.ReadString('WinExePath', 'ExcelPath', ''); if (curServerName = '') or (curDBName = '') then begin tmpServerFrm := TServerFrm.Create(Application); tmpServerFrm.ShowModal; if tmpServerFrm.ModalResult = mrOk then begin curServerName := tmpServerFrm.Edit1.Text; curDBName := tmpServerFrm.Edit2.Text; tempIni.WriteString('SYSTEM', 'SERVER', curServerName); tempIni.WriteString('SYSTEM', 'DBNAME', curDBName); tmpServerFrm.Free; end else begin tmpServerFrm.Free; Halt; end; end; tempIni.Free;end; 首先十分感谢,但BDE是否需要连接配置。 对不起,我要连接ORACLE数据库 BDE连接是比较方便的。 具体设置是:如果连接mssql,必须安装她的驱动程序,然后在bde面板中新建一个数据库,选择驱动程序,选择mssql的数据库。 连接,一般还要输入密码,就ok了!! 对于odbc,我没做过。 我不太喜欢odbc。呵呵 对不起,我要连接ORACLE8数据库,如何?请指教! 是远程连接ORACLE,如何设置? datetime格式的数据属于字符型数据吗?如果不是,怎么转换? 鼠标移到按钮上面时, 按钮有一定的运作回应。 用dbexpress连接MySQL数据库后,设置DBGrid出错!! 再散 关于Chart的一个问题 如何读取MP3的信息? 一个Key的问题? 在Delphi下,如何计算字符串的16位CRC校验码??如何实现??我出100分!! delphi可以拿来编操作系统吗?还是必须用pascal或C?请问用哪种语言编操作系统最好! 如何在任务栏中隐藏 COM方法定义中的参数类型表示什么? 如何拦截滚动条消息
procedure TBasDM.DataModuleCreate(Sender: TObject);
begin
LoginServer; //连接过程
end;
Procedure TBasDM.LoginServer;
var tempIni: TIniFile;
tmpServerFrm: TServerFrm;
i:Integer;
tmpList:TStringList;
IsAliasName:Boolean;
begin IsAliasName:=false;
tmpList:= TStringList.Create;
try
Session.GetAliasNames(tmpList);
for I := 0 to tmpList.Count - 1 do
if tmpList[i]='CostingDB' then
IsAliasName:=true; if not IsAliasName then
Session.AddAlias('CostingDB','MSSQL',CostDB.Params);
finally
tmpList.Free;
end; if CostDB.Connected then
CostDB.Connected := False;
pubLocaOption := [loCaseInsensitive, loPartialKey];
InitDBbasefile; //过程名
with CostDB.Params do
begin
Values['SERVER NAME'] := curServerName;
Values['DATABASE NAME'] := curDBName;
Values['USER NAME'] := 'sa';
Values['PASSWORD'] := '';
end;
try
CostDB.Open;
except
if Application.MessageBox('数据库连接失败,要重新设置吗?','系统',
MB_ICONQUESTION+MB_YESNO)=ID_YES then
begin
tmpServerFrm:=TServerFrm.Create(Application);
tmpServerFrm.ShowModal;
if tmpServerFrm.ModalResult = mrOk then
begin
curServerName := tmpServerFrm.Edit1.Text;
curDBName := tmpServerFrm.Edit2.Text;
tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini');
tempIni.WriteString('SYSTEM', 'SERVER', curServerName);
tempIni.WriteString('SYSTEM', 'DBNAME', curDBName);
tmpServerFrm.Free;
tempIni.Free;
end;
end
else
begin
Application.Terminate;
end;
end;
end;procedure TBasDM.InitDBbasefile;
var
tempIni: TIniFile;
tmpServerFrm: TServerFrm;
begin
tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini');
curServerName := tempIni.ReadString('SYSTEM', 'SERVER', '');
curDBName := tempIni.ReadString('SYSTEM', 'DBNAME', '');
curAutoCADPath := tempIni.ReadString('WinExePath', 'AutoCADPath', '');
curWordPath := tempIni.ReadString('WinExePath', 'WordPath', '');
curExcelPath := tempIni.ReadString('WinExePath', 'ExcelPath', '');
if (curServerName = '') or (curDBName = '') then
begin
tmpServerFrm := TServerFrm.Create(Application);
tmpServerFrm.ShowModal;
if tmpServerFrm.ModalResult = mrOk then
begin
curServerName := tmpServerFrm.Edit1.Text;
curDBName := tmpServerFrm.Edit2.Text;
tempIni.WriteString('SYSTEM', 'SERVER', curServerName);
tempIni.WriteString('SYSTEM', 'DBNAME', curDBName);
tmpServerFrm.Free;
end
else
begin
tmpServerFrm.Free;
Halt;
end;
end;
tempIni.Free;
end;
对于odbc,我没做过。 我不太喜欢odbc。呵呵
请指教!