BLToolkit を介して MSSQL サーバーから返された BIGINT 値から long を取得する最良の方法を知りたいのですが、どちらが良いでしょうか?
long.Parse(db.Parameter("@rowCount").Value.ToString());
また
System.Convert.ToInt64(db.Parameter("@rowCount").Value);
?
BLToolkit を介して MSSQL サーバーから返された BIGINT 値から long を取得する最良の方法を知りたいのですが、どちらが良いでしょうか?
long.Parse(db.Parameter("@rowCount").Value.ToString());
また
System.Convert.ToInt64(db.Parameter("@rowCount").Value);
?
私はこのようにキャストします:
long lngVal = System.Convert.ToLong(db.Parameter("@rowCount").Value);
この場合、理由がないため、以前はオブジェクトを String にキャストしませんでした。
以下は、必要に応じてデータを取得するための良い方法だと思います。
long longValue = 0;
if(db.Parameter("@rowCount").Value!=null)
{
long.TryParse(db.Parameter("@rowCount").Value.ToString(), out longValue);
//longValue: contains the actual long data
}
例外は非常にコストがかかるため、上記のコードに従って例外が処理されます。したがって、より良いアプローチが提供されます。
ありがとう
int nRowCnt = db.GetOrdinals("@rowCount");
db.GetInt64(nRowCnt);
2 番目の形式は、長くとどまるため、優れています。文字列への/からの変換は、2 進数 <-> 10 進数変換により精度が失われる可能性があります。
(long)db.Parameter("@rowCount").Value
または(long?)db.Parameter("@rowCount").Value、値が null になる可能性がある場合に使用します。
1つの方法は、文字列から長いタイプキャストです
((long)(db.Parameter("@rowCount").Value.ToString()))