0

i have a problem with setting the value of the local variable, after i have retrieved the float value from my database. It says it is not the same type, samplerate and the value from (float)rdr["samplerate_hz"]; My code i like this.

    public float hentSampleRateDOEDB(Int64 ekgmaaleid)
    {
        float samplerate = 0.0f;
        connDOEDB.Open();

        SqlCommand cmd = new SqlCommand("SELECT samplerate_hz FROM EKGDATA WHERE ekgmaaleid = '" + ekgmaaleid + "'", connDOEDB);
        SqlDataReader rdr = cmd.ExecuteReader();
        while(rdr.Read())
            samplerate = (float)rdr["samplerate_hz"];
        rdr.Close();
        connDOEDB.Close();
        return samplerate;


    }
Emil
  • 3
  • 2

1 Answers1

0

Maybe try...

samplerate = Convert.ToSingle(rdr["samplerate_hz"]);

Otherwise, I would double check that the "samplerate_hz" column is of type float in the database.