Database
出自VFP Wiki
(修訂版本間差異)
小 |
小 |
||
第37行: | 第37行: | ||
SELECT SNO+','+REMARK FROM DBF_CURSOR | SELECT SNO+','+REMARK FROM DBF_CURSOR | ||
COPY TO abc.txt SDF | COPY TO abc.txt SDF | ||
+ | </pre> | ||
+ | ====如何建立Access檔案(.mdb)==== | ||
+ | =====參考資料===== | ||
+ | 關鍵字:[http://www.google.com.tw/search?q=ADOX ADOX] | ||
+ | *[http://www.motobit.com/tips/detpg_createmdb/ Create MDB database by VBS (ADO/DAO), new MDB file] | ||
+ | *[http://www.dicks-blog.com/archives/2006/01/21/create-mdb-tables-in-vba/ Daily Dose of Create Mdb Tables in VBA] | ||
+ | *[http://forums.databasejournal.com/history/topic.php/40119-1.html DatabaseJournal Forums Archive - Create .mdb table using ADOX] | ||
+ | =====程式碼===== | ||
+ | 感謝狐友 rixw83 的貢獻: | ||
+ | <pre> | ||
+ | ****** Code Start Here *********** | ||
+ | Function xCreateMDB | ||
+ | Lparameter xDatabaseName | ||
+ | |||
+ | If Pcount() <= 0 | ||
+ | Return | ||
+ | Endif | ||
+ | |||
+ | #DEFINE adInteger 3 | ||
+ | #DEFINE adVarWChar 202 | ||
+ | |||
+ | xAdox = CreateObject("Adox.Catalog") | ||
+ | xAdox.Create("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + xDatabaseName + ";") | ||
+ | |||
+ | xTbl = CreateObject("Adox.Table") | ||
+ | |||
+ | With xTbl | ||
+ | .Name = "TestTable" | ||
+ | .Columns.Append("Field1", adVarWChar, 10) | ||
+ | .Columns.Append("Field2", adVarWChar, 10) | ||
+ | .Columns.Append("Field3", adInteger) | ||
+ | EndWith | ||
+ | |||
+ | xAdox.Tables.Append(xTbl) | ||
+ | |||
+ | Release xTbl | ||
+ | Release xAdox | ||
+ | |||
+ | = Messagebox("Done!!") | ||
+ | Return | ||
+ | ****** Code End Here *********** | ||
</pre> | </pre> |
在2007年3月28日 (三) 09:33所做的修訂版本
目錄 |
如何取代資料表中某一欄位的資料
用 REPLACE ... WITH ... 指令. 例如:
REPLACE your_field WITH your_value ALL
或
REPLACE your_field WITH your_value FOR your_condition
如何刪除資料表中某一欄位
使用 ALTER TABLE 指令.
如何匯出資料表格成文字檔
之一
use your_table copy to your_table.txt type sdf * 或者 copy to your_table.txt type csv 亦可
之二
狐友green提供:
set printer to c:\out.txt set print on ? ..... ? ..... set print off set print to
之三
狐友Jack許提供,先用 select-sql 處理,再 copy to
SELECT SNO+','+REMARK FROM DBF_CURSOR COPY TO abc.txt SDF
如何建立Access檔案(.mdb)
參考資料
關鍵字:ADOX
- Create MDB database by VBS (ADO/DAO), new MDB file
- Daily Dose of Create Mdb Tables in VBA
- DatabaseJournal Forums Archive - Create .mdb table using ADOX
程式碼
感謝狐友 rixw83 的貢獻:
****** Code Start Here *********** Function xCreateMDB Lparameter xDatabaseName If Pcount() <= 0 Return Endif #DEFINE adInteger 3 #DEFINE adVarWChar 202 xAdox = CreateObject("Adox.Catalog") xAdox.Create("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " + xDatabaseName + ";") xTbl = CreateObject("Adox.Table") With xTbl .Name = "TestTable" .Columns.Append("Field1", adVarWChar, 10) .Columns.Append("Field2", adVarWChar, 10) .Columns.Append("Field3", adInteger) EndWith xAdox.Tables.Append(xTbl) Release xTbl Release xAdox = Messagebox("Done!!") Return ****** Code End Here ***********