[求教]請問Typed DataSets和Untyped DataSets的分別

本帖最後由 Bread_Lee 於 2018-9-29 17:06 編輯

最近學習.net的database程式,但學到Typed DataSets 和 Untyped DataSets就完全唔明,查過MS的網站和Goggle search,佢地一大段文章,睇完都唔明.
請問有無前輩簡單一兩句可以說明他們的分別.

十分謝謝!

本帖最後由 xader 於 2018-9-29 21:53 編輯
最近學習.net的database程式,但學到Typed DataSets 和 Untyped DataSets就完全唔明,查過MS的網站和Goggle s ...
Bread_Lee 發表於 2018-9-29 17:05



    https://docs.microsoft.com/en-us ... tasets?view=vs-2017

簡單 D 講, typed dataset 係佢知你個 schema
所以係 coding time 已經可以話俾你知你寫錯野

untyped dataset 要去到 compile time 先爆 exception,
但係你唔洗話佢知你個 schema 係咩 (特別係你唔知佢個 schema 而家係咩樣的話)

TOP

簡單 D 講, typed dataset 係佢知你個 schema
所以係 coding time 已經可以話俾你知你寫錯野

unt ...
xader 發表於 2018-9-29 21:42

非常多謝回答,但都唔係太明.
Typed DataSets和Untyped DataSets係咪都係指同一個dataset?

TOP

非常多謝回答,但都唔係太明.
Typed DataSets和Untyped DataSets係咪都係指同一個dataset? ...
Bread_Lee 發表於 2018-9-29 22:58



    for example

我有一個 Table, 有兩個 column
一個係 ID (Int), 另一個係 Description(Varchar)

Typed Dataset 知道你個 Table 兩個 Column 的 type, 一個係 Int, 另一個係 Varchar
所以佢會識幫你
int id = northwindDataSet.Customers[0].ID; << Implicit type conversion

Untyped Dataset 唔知你個 Table 兩個 Column 的 type, 一個係 ???(object), 另一個係 ???(object)
所以
int id =  northwindDataSet.Customers[0].ID <<左手面係 int type, 右手面係 ???(object), 咁就會係 compile time 話你錯

不過如果你指錯 field
例如
int id= (int) northwindDataSet.Customers[0].Description 的話, 咁就要去到 runtime throw exception

TOP