Format date (dd / MM / yyyy)

1

I have here a column in a DataGridview with the name "DBO" (date of birth) that is in the month / day / year format, I wanted to change the date style to dd-MM-yyyy but I can not.

    myCommand = "UPDATE DoctorBasic SET " & _
    "DOB = '" & Convert_Null(DGV1(9, 0).Value.ToString("dd/MM/yyyy"), #1/1/1900#)** & "' " & _
    "WHERE DoctorId = " & DGV1(0, 0).Value

    cmd = New SqlCommand(myCommand, myConnectionString)
    MsgBox(myCommand)
    cmd.Connection.Open()
    cmd.ExecuteNonQuery()
    cmd.Connection.Close()

The convert_null is intended to display this date 1/1/1900 as default if the record you are looking for does not have a date and you want to record some changes to avoid error because the field is null.

    
asked by anonymous 22.01.2015 / 13:36

2 answers

2

Make the change in SQL, since you are using SQL manual for update :

myCommand = "UPDATE DoctorBasic SET " & _
"DOB = convert(datetime, '" & Convert_Null(DGV1(9, 0).Value.ToString("dd/MM/yyyy"), #1/1/1900#)** & "', 103) " & _
"WHERE DoctorId = " & DGV1(0, 0).Value

The specification of CONVERT() with format 103 can be read here .

    
22.01.2015 / 13:41
0
Algumas dicas :

To play data within the datagrid, it can be left with text, you can see when to send order, in relation to day / month / year, to stay as date, stay on the null question, that there must be a treatment , but often it must be null, so complicate, because it comes more treatment, if left with text, it is easier to treat, think about it.

In the format question, you can use string.format.

    
01.03.2015 / 23:39