1
I need to make a insert
of the date with the monthCalendar
in C#
in the database MySQL
, only that the format of the date of MySQL
is (yyyy-MM-dd
) and I’ve already modified the code :
I modified the input mode (yyyy-MM-dd
)
cadast.Dataa=Convert.ToDateTime(monthCalendar1.SelectionStart.Date.ToString("yyyy-MM-dd"));
And modified in the class that makes the insert
in the database:
string inserir = "INSERT INTO consultas (Dataa,Horario, cd_paciente, cro, cd_procedimento) values (str_to_date('" + cadast.Dataa + "','%Y-%m-%d'),'"+cadast.Horario+ "', '" + cadast.cd_paciente + "','" + cadast.cro + "' ,'" + cadast.cd_procedimento + "')";
And he presents the following error:
Command error Correct datetime value: '30/11/2016 00:00:00' for Function str_to_date.
I modified the insert
for:
string inserir = "INSERT INTO consultas (Dataa,Horario, cd_paciente, cro, cd_procedimento) values (str_to_date('" + cadast.Dataa + "','%Y-%m-%d %h:%i:%s %p'),'"+cadast.Horario+ "', '" + cadast.cd_paciente + "','" + cadast.cro + "' ,'" + cadast.cd_procedimento + "')";
and modified in the field of calendario(MonthCalendar)
to see if the problem was in him:
cadast.Dataa=
Convert.ToDateTime(monthCalendar1.SelectionStart.Date.ToString("%Y-%m-%d %h:%i:%s%p"));
Then he presented the following error:
The string was not recognized as a valid Datetime. There is an unknown word that starts at index 0.
It didn’t work either I’ve tried every possible way and so far I haven’t succeeded, someone can help me?
yes, only that my code is already done, I would not like to mess with its structure, because it is working perfectly...only that the problem is that in the use of monthcalendar is not accepting the date input that I am passing on the code to it.
– Andressa Santos
@Andressasantos follow this answer and many others here with this style, because, it makes the automatic conversion internally in recording the data in the table, in changing what has already done, touch the structure, this is important for your learning and growth. This tip will solve your problems not only from now on. + 1 for the answer
– novic
All right, thank you...I’ll try to change and do some research here.. Thank you
– Andressa Santos