2014/09/28

在 MAC OS X 取得 Address Book

使用 AddressBook framework
//取得 Address 物件
ABAddressBook *ab = [ABAddressBook sharedAddressBook];

//取得"自己"的資料
ABPerson *me = [ab me];
NSString *fName = [me valueForProperty:kABFirstNameProperty];
NSString *lName = [me valueForProperty:kABLastNameProperty];

//設定資料
[me setValue:@"Candan" forProperty:kABFirstNameProperty];

//取得所有人員的 Array
NSArray *everyone = [ab people];

//取得人員群組
NSArray *groups = [ab groups];

//新增一筆人員資料
ABPerson *newPerson = [[ABPerson alloc] init];

//將人員加入 AddressBook
[ab addRecord: newPerson];

//將人員從 AddressBook 移除
[ab removeRecord: me];

//設定"自己"是誰
[ab setMe:newPerson];

//AddressBook 儲存
[ab save];

2014/09/06

updatecommand 已經影響必須是 1 記錄的 0

.NET 開發時,有時會遇到"updatecommand 已經影響必須是 1 記錄的 0"這樣的錯誤訊息

這個錯誤訊息的意思是,DataRow 中包含的原始資料已經在資料庫找不到了,有可能是資料庫的資料已經被其他人改過,也有可能 DataRow 包含了錯誤訊息。其實在 DataRow 中含有修改前的資料與修改後的資料,可以透過 DataRowVersion.Original 的方式可以存取到修改前的資料(請參考 http://msdn.microsoft.com/zh-tw/library/ms135373(v=vs.110).aspx),DataAdapter會依據 DataRowVersion.Original 中含有的資料去資料庫找,並更新該筆資料,若依據 DataRowVersion.Original 的資料在資料庫中找不到符合的資料就會出現"updatecommand 已經影響必須是 1 記錄的 0" 的錯誤訊息。

若發生這個錯誤時,先確定資料庫的資料是否被其他人異動過。若不是,就透過 DataRowVersion.Original 去找尋那一個欄位的資料值是有問題,找找看程式是否拿到更早的資料或是查錯資料表。

若資料存進資料庫成功後,可以執行 DataTable.AcceptChanges(); ,這個動作會將現在的資料複製到  DataRowVersion.Original 的資料中,來確保資料庫的資料已經跟 DataTable 是一致的了,下次存資料庫時,才不會因為資料不一致又發生 "updatecommand 已經影響必須是 1 記錄的 0" 的錯誤訊息。

2014/09/01

在 Mac 增加 STATIC ROUTE

Candan$ ifconfig en1
en1: flags=8863 mtu 1500
ether xx:xx:xx:xx:xx:xx 
inet6 fe80::fa1e:dfff:fee0:ad95%en1 prefixlen 64 scopeid 0x5 
inet 192.168.1.101 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=1
media: autoselect

status: active

Candan$ sudo route add -net 192l168.2.0/24 192.168.1.3
Password:
add net 192.168.2.0: gateway 192.168.1.3