procedure TForm1.BitBtn2Click(Sender: TObject); begin try Ta:=TRegistry.Create; Tb:=TRegistry.Create; Ta.RootKey:=HKEY_LOCAL_MACHINE; if not Ta.OpenKey('software\odbc\odbc.ini\'+edit2.text+'\',true) then begin ta.OpenKey('software\odbc\odbc.ini\',true); ta.CreateKey(edit2.text); end; ta.WriteString('database',edit2.text); ta.WriteString('driver','c:\winnt\system32\sqlsrv32.dll'); ta.WriteString('lastuser','sa'); ta.writestring('server','(local)'); ta.WriteString('Trusted_Connection','yes'); //The second key for driver a odbc Tb.RootKey:=Ta.RootKey; Tb.OpenKey('software\odbc\odbc.ini\odbc data sources\',true); tb.WriteString(edit2.text,'SQL SERVER'); except showmessage('error'); end; { if not Ta.ValueExists(edit1.text) then ///////// begin Ta.CreateKey(edit1.text); end; } end;这是我做过的一个例子,你看看吧
begin
try
Ta:=TRegistry.Create;
Tb:=TRegistry.Create;
Ta.RootKey:=HKEY_LOCAL_MACHINE;
if not Ta.OpenKey('software\odbc\odbc.ini\'+edit2.text+'\',true) then
begin
ta.OpenKey('software\odbc\odbc.ini\',true);
ta.CreateKey(edit2.text);
end;
ta.WriteString('database',edit2.text);
ta.WriteString('driver','c:\winnt\system32\sqlsrv32.dll');
ta.WriteString('lastuser','sa');
ta.writestring('server','(local)');
ta.WriteString('Trusted_Connection','yes');
//The second key for driver a odbc
Tb.RootKey:=Ta.RootKey;
Tb.OpenKey('software\odbc\odbc.ini\odbc data sources\',true);
tb.WriteString(edit2.text,'SQL SERVER');
except
showmessage('error');
end;
{ if not Ta.ValueExists(edit1.text) then /////////
begin
Ta.CreateKey(edit1.text);
end; }
end;这是我做过的一个例子,你看看吧
SQLConfigDataSource.
SQLManageDataSources
SQLConfigDataSource 在哪里找?delphi哪个头文件里面有?
SQLConfigDataSource.
SQLManageDataSources
SQLConfigDataSource 在哪里找?delphi哪个头文件里面有?
SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,'SQL Server', //ODBC_ADD_SYS_DSN是常量
'DSN='+ DSN + chr(0) + //需要定义为4
'Server='+ Server + chr(0) +
'Database='+ DBName + chr(0) +
'Description=ODBC Source'+ chr(0));