利用Opendialog開啟Access資料庫 |
答題得分者是:pceyes
|
what001
一般會員 發表:7 回覆:6 積分:2 註冊:2008-11-25 發送簡訊給我 |
|
careychen
尊榮會員 發表:41 回覆:580 積分:959 註冊:2004-03-03 發送簡訊給我 |
用 Opendialog 開啟資料庫,您是自己寫 ACCESS 嗎? 用完 Opendialog 後,
您說的 Filter 是指哪裏的? TADOQuery ? 資料庫用 dbGrid 開啟? 這又是怎麼操作的? 建議您再描述清楚一點!! (其實大概知道您要問什麼,但發問者把問題寫清楚一點,也能讓更多的前輩您的問題!! ^^) ===================引 用 what001 文 章=================== 請問可否利用Opendialog開啟資料庫呢? 我想利用下拉式選單的方式開啟資料庫, 我已經將filter中設了mdb檔了,但是資料庫似乎沒辦法在dbgrid中開啟! 所以不曉得是不是無法利用opendialog開啟呢? 先謝謝大家的回答!
------
價值的展現,來自於你用哪一個角度來看待它!! |
pceyes
尊榮會員 發表:70 回覆:657 積分:1140 註冊:2003-03-13 發送簡訊給我 |
unit1.pas
[code delphi] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids; type TForm1 = class(TForm) DBGrid1: TDBGrid; OpenDialog1: TOpenDialog; ADOConnection1: TADOConnection; ADOTable1: TADOTable; DataSource1: TDataSource; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; MyFormat_ConnectionStr : string; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if opendialog1.Execute then begin ADOConnection1.Connected := false; AdoTable1.Active := false; ADOConnection1.ConnectionString := format(MyFormat_ConnectionStr,[opendialog1.FileName]); ADOConnection1.Connected := true; AdoTable1.Active := true; end; end; procedure TForm1.FormCreate(Sender: TObject); begin MyFormat_ConnectionStr := ADOConnection1.ConnectionString ; end; end. [/code] unit1.dfm [code delphi] object Form1: TForm1 Left = 192 Top = 107 Width = 544 Height = 375 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 48 Top = 96 Width = 449 Height = 201 DataSource = DataSource1 ImeName = '中文 (繁體) - 倉頡' TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = [] end object Button1: TButton Left = 320 Top = 24 Width = 169 Height = 57 Caption = 'Button1' TabOrder = 1 OnClick = Button1Click end object OpenDialog1: TOpenDialog Left = 48 Top = 24 end object ADOConnection1: TADOConnection ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security' // 注意這裏 ' Info=False' LoginPrompt = False Provider = 'Microsoft.Jet.OLEDB.4.0' Left = 160 Top = 24 end object ADOTable1: TADOTable Connection = ADOConnection1 TableName = 'master' Left = 208 Top = 24 end object DataSource1: TDataSource DataSet = ADOTable1 Left = 248 Top = 24 end end [/code]
------
努力會更接近成功 |
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
只提供一個觀念, 因為程式碼樓上的大大已經提供了
OpenDialog 只是做為要選擇那一個檔案來開啟之用, 就好像我要從一箱的水果籃中拿出一個蘋果(裡面有各式各樣的水果, 橘子, 木瓜, 西瓜, 蘋果...), 這就是OpenDialog的功能, 至於拿出來後, 這個水果要怎麼切, 則要看這個水果是什麼型式, 選擇適用的刀子來操作, 這如 mdb 要用什麼來開啟一樣, 無關於OpenDialog 不知這樣明白否? ===================引 用 what001 文 章=================== 請問可否利用Opendialog開啟資料庫呢? 我想利用下拉式選單的方式開啟資料庫, 我已經將filter中設了mdb檔了,但是資料庫似乎沒辦法在dbgrid中開啟! 所以不曉得是不是無法利用opendialog開啟呢? 先謝謝大家的回答! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |