4
Hi,
You are selecting only one record as sum so use dr.GetDecimal(0) as shown
- txttotalamountpaid.Text = Convert.ToString(dr.GetDecimal(0));
3
Hello,
Few things to note here:
1/ It should be dr.GetInt32(0).ToString() as it is the first column in the resultset.
2/ Make sure the returning value is of data type Int. Your SQL Server column is decimal, hence you should be requesting a Decimal column.
3/ Because you are getting just one value, you are better of using ExecuteScalar instead of ExecuteReader.
4/ Try to avoid directly accessing database in your application. Use layered approach. Abstract functionality and use objects to fetch data.
5/ Pretty much all your columns are nvarchar(50). This does not look good. Use correct data types.
2
Hi,
Please refer this thread,
https://stackoverflow.com/questions/53065091/how-to-get-number-value-with-decimal-from-datareader
2
The reason why it is showing indexoutofrange exception because in dr.GetInt32(6) the index 6 is not present. So you can use the index which is present. Thanks
2
Because datatype of CashReceived column is Decimal(18,2), you should use the "GetDecimal"
method of SqlDataReader
. A SqlDataReader
object implmements the IDataRecord
interface. Hence, it implements many methods. Among these methods, there is the GetDecimal
.
Try this:
txttotalamountpaid.Text = Convert.ToString(dr.GetDecimal(0));