user3362508
user3362508

Reputation: 1

casting exception when I converting a decimal to a string in a ODBCdatareader

I am getting a casting exception when I converting a decimal to a string in a ODBCdatareader.

  string balanceTotal = "SELECT SUM(BalanceRemaining)  FROM Invoice WHERE  (CustomerRefFullName = '" + comboBox1.DisplayMember + "')";
            OdbcDataReader myReader;
            sqlConnect conect = new sqlConnect();
            conect.sqlReader(balanceTotal);
            myReader = conect.sqlReader(balanceTotal).ExecuteReader(); 
                while (myReader.Read())
                {
                    String name = myReader.GetDecimal(0).ToString();
                    textBox1.Text = name;
                }   

Cant figure it out

Upvotes: 0

Views: 55

Answers (1)

wizulus
wizulus

Reputation: 6363

BalanceRemaining may not be a Decimal.

Use myReader.GetValue(0) first, then inspect the type of object it gives you. Then you will know it's safe to cast as that type.

Upvotes: 1

Related Questions