ADOConnection如何动态连接数据库? 如上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ADOConnection1.Connected:=false; tempPath:=ExtractFilePath(Application.ExeName)+'\DBNAME.mdb'; tempStr:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source='; tempStr:=tempStr+tempPath; tempStr:=tempStr+';Mode=ReadWrite;Extended Properties="";'; tempStr:=tempStr+'Locale Identifier=2052;'; tempStr:=tempStr+'Persist Security Info=False;'; tempStr:=tempStr+'Jet OLEDB:System database="";'; tempStr:=tempStr+'Jet OLEDB:Registry Path="";'; tempStr:=tempStr+'Jet OLEDB:Database Password="";'; tempStr:=tempStr+'Jet OLEDB:Engine Type=5;'; tempStr:=tempStr+'Jet OLEDB:Database Locking Mode=1;'; tempStr:=tempStr+'Jet OLEDB:Global Partial Bulk Ops=2;'; tempStr:=tempStr+'Jet OLEDB:Global Bulk Transactions=1;'; tempStr:=tempStr+'Jet OLEDB:New Database Password="";'; tempStr:=tempStr+'Jet OLEDB:Create System Database=False;'; tempStr:=tempStr+'Jet OLEDB:Encrypt Database=False;'; tempStr:=tempStr+'Jet OLEDB:Don''t Copy Locale on Compact=False;'; tempStr:=tempStr+'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False'; ADOConnection1.ConnectionString:=TempStr; TRy ADOConnection1.Connected:=True; except ShowMessage('数据库连接出现错误'); exit; const connectstringA ='Provider=MSDataShape.1;Persist Security Info=True;Data Source='; connectstringB =';Data Provider=Microsoft.Jet.OLEDB.4.0';tempquery:=Tadoquery.create(nil); try ADOConnection.Free; ADOConnection:=TADOConnection.create(Application); ADOConnection.connectionstring:=connectstringA + 'd:\test.mdb' + connectstringB; ADOConnection.LoginPrompt:=False; tempquery.connection:=AdoConnection; tempquery.Close; tempquery.SQL.Clear; tempquery.SQL.Add(SqlClause); tempquery.open; var DataBaseName, ConnectStr:ansiString; passwordform:tpasswordform; i:integer; RationDataBaseName : AnsiString;begin flag:=false; listbox1.Items.Clear; OpenDialog1.Title:='打开工程项目'; OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName) + '新建项目'; if OpenDialog1.Execute then begin //设置连接字符串 DataBaseName:=OpenDialog1.FileName; ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';'; ProjectDatamodule.ProjectConnection.Connected:=false; ProjectDatamodule.ProjectConnection.ConnectionString:=''; ProjectDatamodule.ProjectConnection.ConnectionString:=ConnectStr+'Persist Security Info=true'; ProjectDatamodule.ProjectConnection.Connected:=true; projectdatamodule.Projectconnection.GetTableNames(listbox1.Items,false); 哦。对不起,我想说的是如何调用Delphi中BuildConnectionString的那个界面来生成ConnectionString Adodb.pas中有个函数PromptDataSource(handle,'...');//'...'为你初始化的字符串.返回的是一个wideString.就是连接.可以用它来实现你的要求. var InitialString: WideString;begin InitialString:=''; InitialString:=PromptDataSource(Handle,''); if InitialString<>'' then begin ADOConCost.Connected:=False; ADOConCost.ConnectionString:= InitialString; ADOConCost.Connected:=True; end;end; 用ini文件 ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False'+ ';User ID='+username+';Password=sa'+';Initial Catalog=manage'+ ';Data Source='+servername+';'; ADOConnection1.ConnectionString:=ConnectionString;manage为库名,此例为sql server2000 delphi的Udl文件能连接到sql2005吗?应该如何设置,如果不行,用语句怎么连接? 貌似简单很有难度的算法 Tdatabase控件中的一个属性值的问题 ISAPI下调用HTTP接口的问题 如何实现数据录入框在数据录入无效时给与提示? 如何实现查询(实时更新并将结果更新)急!!!分数不够可在加。 如何获取qq信息包的内容?? 您好,请问怎样去掉字符串中间的空格?谢谢 请问如何在dll中创建socket?请给出代码,非常急~~!! 关于combobox自画问题。 建立快捷方式,马上给高分。 请问怎样隐藏任务拦上指定程序的图标,
tempPath:=ExtractFilePath(Application.ExeName)+'\DBNAME.mdb';
tempStr:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=';
tempStr:=tempStr+tempPath;
tempStr:=tempStr+';Mode=ReadWrite;Extended Properties="";';
tempStr:=tempStr+'Locale Identifier=2052;';
tempStr:=tempStr+'Persist Security Info=False;';
tempStr:=tempStr+'Jet OLEDB:System database="";';
tempStr:=tempStr+'Jet OLEDB:Registry Path="";';
tempStr:=tempStr+'Jet OLEDB:Database Password="";';
tempStr:=tempStr+'Jet OLEDB:Engine Type=5;';
tempStr:=tempStr+'Jet OLEDB:Database Locking Mode=1;';
tempStr:=tempStr+'Jet OLEDB:Global Partial Bulk Ops=2;';
tempStr:=tempStr+'Jet OLEDB:Global Bulk Transactions=1;';
tempStr:=tempStr+'Jet OLEDB:New Database Password="";';
tempStr:=tempStr+'Jet OLEDB:Create System Database=False;';
tempStr:=tempStr+'Jet OLEDB:Encrypt Database=False;';
tempStr:=tempStr+'Jet OLEDB:Don''t Copy Locale on Compact=False;';
tempStr:=tempStr+'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
ADOConnection1.ConnectionString:=TempStr;
TRy
ADOConnection1.Connected:=True;
except
ShowMessage('数据库连接出现错误');
exit;
connectstringA ='Provider=MSDataShape.1;Persist Security Info=True;Data Source=';
connectstringB =';Data Provider=Microsoft.Jet.OLEDB.4.0';tempquery:=Tadoquery.create(nil);
try
ADOConnection.Free;
ADOConnection:=TADOConnection.create(Application);
ADOConnection.connectionstring:=connectstringA + 'd:\test.mdb'
+ connectstringB;
ADOConnection.LoginPrompt:=False;
tempquery.connection:=AdoConnection;
tempquery.Close;
tempquery.SQL.Clear;
tempquery.SQL.Add(SqlClause);
tempquery.open;
ConnectStr:ansiString;
passwordform:tpasswordform;
i:integer;
RationDataBaseName : AnsiString;
begin
flag:=false;
listbox1.Items.Clear;
OpenDialog1.Title:='打开工程项目';
OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName) + '新建项目';
if OpenDialog1.Execute then
begin
//设置连接字符串
DataBaseName:=OpenDialog1.FileName;
ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';';
ProjectDatamodule.ProjectConnection.Connected:=false;
ProjectDatamodule.ProjectConnection.ConnectionString:='';
ProjectDatamodule.ProjectConnection.ConnectionString:=ConnectStr+'Persist Security Info=true';
ProjectDatamodule.ProjectConnection.Connected:=true;
projectdatamodule.Projectconnection.GetTableNames(listbox1.Items,false);
PromptDataSource(handle,'...');//'...'为你初始化的字符串.
返回的是一个wideString.就是连接.
可以用它来实现你的要求.
InitialString: WideString;
begin
InitialString:='';
InitialString:=PromptDataSource(Handle,'');
if InitialString<>'' then begin
ADOConCost.Connected:=False;
ADOConCost.ConnectionString:= InitialString;
ADOConCost.Connected:=True;
end;
end;
ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False'+
';User ID='+username+';Password=sa'+';Initial Catalog=manage'+
';Data Source='+servername+';';
ADOConnection1.ConnectionString:=ConnectionString;
manage为库名,此例为sql server2000