1、我使用ACCESS做數據庫,每次換電腦或用其它用戶登陸時,又要通過ODBC重新在連過,怎麼樣解決?
2、幾個按鍵,分別寫成了新增、修改、刪除、保存,如何在新增,保存後,數據能顯示在DBGRID,好像是讓數據刷新一遍,如何刷新,萬望詳細一點。
2、幾個按鍵,分別寫成了新增、修改、刪除、保存,如何在新增,保存後,數據能顯示在DBGRID,好像是讓數據刷新一遍,如何刷新,萬望詳細一點。
调试欢乐多
2、把你的数据集关闭再打开就可以了。
2.在操作之后,用Refresh刷新,如果不行就close,open一次刷新。
我再附加一段動態創建dsn的代碼function Create_ODBC_DSN(const aDSNName, aDriverName, aDatabasePath: string): boolean;
var
mReg: TRegistry;
bData: array[0..0] of byte;
begin
Result := False;
mReg := TRegistry.Create;
try
mReg.RootKey := HKEY_CURRENT_USER; {!!!!HKEY_LOCAL_MACHINE???}
if mReg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True) then
begin //註冊一個DSN名稱
mReg.WriteString(aDSNName, aDriverName);
end
else
begin //創建鍵值失敗
Exit;
end;
mReg.CloseKey;
{找到或創建Software\ODBC\ODBC.INI\MyAccess, 寫入DSN配置資訊}
if mReg.OpenKey('Software\ODBC\ODBC.INI\' + aDSNName, True) then
begin
mReg.WriteString('DBQ', aDatabasePath); //資料庫目錄
mReg.WriteString('Description', DSN_DTS_DESCRIPT); //資料源描述
mReg.WriteString('Driver', GetSystem32Dir() + '\SYSTEM32\odbcjt32.dll'); //驅動程式DLL文件
mReg.WriteInteger('DriverId', 25); //驅動程式標識
mReg.WriteString('FIL', 'Ms Access;'); //!!!Filter依據
mReg.WriteInteger('SafeTransaction', 0); //支援的事務運算元目
mReg.WriteString('UID', ''); //用戶名稱
bData[0] := 0;
mReg.WriteBinaryData('Exclusive', bData, 1); //非獨占方式
mReg.WriteBinaryData('ReadOnly', bData, 1); //非唯讀方式
end
else //創建鍵值失敗
begin
Exit;
end;
mReg.CloseKey;
//找到或創建Software\ODBC\ODBC.INI\ %s \Engines\Jet寫入DSN資料庫引擎配置資訊
if mReg.OpenKey(Format('Software\ODBC\ODBC.INI\%s\Engines\Jet', [aDSNName]), True) then
begin
mReg.WriteString('ImplicitCommitSync', 'Yes');
mReg.WriteInteger('MaxBufferSize', 512); //緩衝區大小
mReg.WriteInteger('PageTimeout', 10); //頁超時
mReg.WriteInteger('Threads', 3); //支援的線程數目
mReg.WriteString('UserCommitSync', 'Yes');
end
else //創建鍵值失敗
begin
Exit;
end;
Result := True;
finally
mReg.CloseKey;
mReg.Free;
end;
end;
2,用一个adoquery1就可以了,每次通过对数据库的增加,删除,修改等操作就可以很方便的搞顶
具体来说,网上很多例子!
比如删除:
with adoquery1 do
begin
sql.close;
sql.clear;
sql.add('delete from table where 字段A=a');//这样就可以删除了,其他地方的操作类似
execsql;
end;
begin
if Connected = True then
Close;
ConnectionString := GetConnectString('access文件完整路径!');
LoginPrompt := False;
Open('Admin', '');
endfunction GetConnectString(dataPath: string): string;//数据库的路径
begin
Result := '';
if sSource <> '' then
Result := 'Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;' +
'Data Source=' + dataPath+ ';User ID=Admin;Jet OLEDB:Database Password=' +
密码;
end;我觉得这种连接方法更适合你