Valerie Meunier

Valerie Meunier

  • 1.7k
  • 462
  • 21k

problem with date

Apr 5 2022 2:16 PM

Hi

Sqlserver: field 'dat' has type 'Date' (not DateTime). One present date in that field is e.g.: 2018-01-12.

With some code, i put the table (2 fields: one date and one string) in a datagridview which shows the date as : 12/01/2018. That's normal because my Windows has the european format (day/month/year).. No problem so far.

Now, when i click on the left of the colums in the datagridview, the present value of the 2 fields is copied into 2 textbox like this:

 private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString() != "")
            {
                wID = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            }
            else
            {
                textBox1.Text = "";
                textBox2.Text = "";
                wID = "";
            }

My first problem is: the date 12/01/2018 is now shown in the textbox like this: 12/01/2018 0:00:00. How can i fix that?

My second problem is when i update the row: when i put 05/04/2022 (for me the day today), the date in sqlserver is 2022-05-04 while i want to get 2022-04-04.

Thanks for help.

V


Answers (3)