I have SqlDataReader which fills multiple textboxes, but the issue is when they are NULL I get an exception which I dont know how to handle.
SqlCommand command = new SqlCommand("SELECT * FROM zajezd WHERE akce='" + akce + "' and rocnik='" + klientClass.Rocnik() + "'", spojeni);
spojeni.Open();
SqlDataReader read= command .ExecuteReader();
if (read.Read())
{
s_ub_cen.Text = read.GetDecimal(59).ToString();
object nulldate = (s_ub_dat.Text = read.IsDBNull(61) ?
string.Empty : read.GetDateTime(61).ToShortDateString());
}
Exception: System.Data.SqlTypes.SqlNullValueException: Data are null.
I have like 20 Textboxes, is there any easy solution? I would like to leave the textboxes empty when the value is null, everything is working fine for ShortDatString.
I need to figure out how to handle this like when value from DB is NULL:
s_ub_cen.Text = precti2.GetDecimal(59).ToString();
Thank you so much.