Question

Hello guys I have this code, I have issue when I execute:

zodjdate.Text = precti.GetDataTypeName(24);

or

zpridate.Text = precti.GetDataTypeName(23);

It only shows date in that textBox. I would like to know if there is any way it can show the full date which is saved in SQL DB?

this is the full code

        SqlCommand novyprikaz = new SqlCommand("SELECT * FROM zajezd WHERE akce="+nc_zajezd_vyber, spojeni); 
        spojeni.Open();
        SqlDataReader precti = novyprikaz.ExecuteReader();

        if (precti.Read())
        {

            zodjdate.Text = precti.GetDataTypeName(24);
            zpridate.Text = precti.GetDataTypeName(23);

        }
        spojeni.Close();
    }
Was it helpful?

Solution

You are using GetDataTypeName for the dates, so it is showing the correct info. What you want is GetDateTime. More specifically, change the following two lines:

        zodjdate.Text = precti.GetDataTypeName(24);
        zpridate.Text = precti.GetDataTypeName(23);

to

        zodjdate.Text = precti.GetDateTime(24).ToShortDateString();
        zpridate.Text = precti.GetDateTime(23).ToShortDateString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top