I have this code:
public void nactiData()
{
SqlCommand cm = new SqlCommand("SELECT * FROM zajezd WHERE akce="+nc_zajezd_vyber, con);
con.Open();
SqlDataReader reader = cm.ExecuteReader();
if (reader.Read())
{
zpocdnu.Text = reader.GetInt32(31).ToString();
zcena3.Text = reader.GetDecimal(6).ToString();
}
con.Close();
}
Problem is that it doesn't read zcena3 because the datatype in the table is numeric.
On Microsoft's website is written that I should read it with GetDecimal, but it doesn't work either.
Is there any solution?
*with column positions is asking for trouble. Write out the column names, likeGetString("col1")int,smallintorbigint; you need to use.GetInt16/.GetInt32/.GetInt64(not.GetDecimal). You said usingGetDecimaldoesn't work - how does it not work? Do you get an error? If so: what error ?reader.GetString(reader.GetOrdinal("col1"))(and typically the result of callingGetOrdinalwould be executed only once and then cached in a variable).