2

I would like to know the best way to obtain long from returned BIGINT value from MSSQL server via BLToolkit which will be better?

long.Parse(db.Parameter("@rowCount").Value.ToString());

or

System.Convert.ToInt64(db.Parameter("@rowCount").Value);

?

Alexei
  • 1,289
  • 3
  • 19
  • 34

6 Answers6

2

i would cast like this:

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

In this case I would not cast the object to String before, because there is no reason for it.

Developer
  • 393
  • 1
  • 1
  • 8
1

I think below is a good way to retrieve data as you wanted:

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

Since exception is very costly and according to above code exception is handled. So it will provide better approach.

Thanks

Elias Hossain
  • 4,410
  • 1
  • 19
  • 33
0

The second form is better as it stays a long. Converting to/from a string might potentially lose precision due to binary<->decimal conversions.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
0

use (long)db.Parameter("@rowCount").Value or (long?)db.Parameter("@rowCount").Value if your value could be null.

  • If the Value could be null, you shouldn't use this prefix-cast. Prefer a as-cast if the value could be null, because of performance. – Benni Mar 05 '12 at 10:22
0

one way is type cast it long from string

((long)(db.Parameter("@rowCount").Value.ToString()))
Asif Mukhida
  • 142
  • 2
0
int nRowCnt = db.GetOrdinals("@rowCount");
db.GetInt64(nRowCnt);
Shivaram
  • 41
  • 5