2012-03-05 58 views

回答

0

第二種形式更好,因爲它停留很長。由於二進制< - >十進制轉換,轉換爲字符串/從字符串轉換可能會失去精度。

0

使用(long)db.Parameter("@rowCount").Value(long?)db.Parameter("@rowCount").Value如果您的值可能爲空。

+0

如果值可能爲空,則不應使用此前綴轉換。由於性能原因,如果值可能爲空,則優先使用鑄態。 – Benni 2012-03-05 10:22:40

0

一種方法是長類型轉換從字符串

((long)(db.Parameter("@rowCount").Value.ToString())) 
0

我會投這樣的:

long lngVal = System.Convert.ToLong(db.Parameter("@rowCount").Value); 

在這種情況下我也不會之前的對象轉換爲字符串,因爲沒有它的原因。

0
int nRowCnt = db.GetOrdinals("@rowCount"); 
db.GetInt64(nRowCnt); 
1

我認爲下面是你想要檢索數據的好方法:

long longValue = 0; 
if(db.Parameter("@rowCount").Value!=null) 
{ 
    long.TryParse(db.Parameter("@rowCount").Value.ToString(), out longValue); 
    //longValue: contains the actual long data 
} 

由於異常是非常昂貴的,並根據上面的代碼處理異常。所以它會提供更好的方法。

謝謝

相關問題