1

Unsure why I am recieving this error as converting other columns has worked fine.

Basically I have a SELECT statement which plays back int/string/float. The following code only throws the above error on the float, however within the Database/ViewModel they are both of type Float.

VIEWMODEL

public float personalAmount { get; set; }

REPOSITORY

     string selectQuery = "SELECT OC.[id], OC.[number_id], ONU.[mobile_number], OC.[personal_amount], OC.[start_date], OC.[end_date] " +
                                "FROM export OC " +
                                    "INNER JOIN numbers ONU ON OC.number_id = ONU.number_id " +
                                "WHERE OC.[person_id] = " + id;
        SqlCommand myCommand = new SqlCommand(selectQuery);
        myCommand.Connection = myConnection;
        myConnection.Open();

        SqlDataReader dataReader = myCommand.ExecuteReader();
        if (!dataReader.HasRows) return null;

        var newData = new List<List>();
        while (dataReader.Read())
        {
            List list = new List();
            list.id = (int)dataReader["id"];
            list.mobileNumber = dataReader["mobile_number"].ToString();
            list.personalAmount = (float) dataReader["personal_amount"];
            list.startDate = (DateTime)dataReader["start_date"];
            list.endDate = (DateTime)dataReader["end_date"];

            newData.Add(list);
        }
        dataReader.Close();

Thanks in advance for any help :-)

Clare

4

1 回答 1

3

Have you tried doing a Float.Parse(dataReader["personal_amount"].ToString())?

It's not a cool way of solving, but it may work.

于 2012-07-17T09:30:23.277 回答