0

I am having trouble saving dates to my MySQL database (code below)

C#

    var abook = db.egw_addressbook.Local.FirstOrDefault(o => o.contact_id == 16875);
    abook.org_name = mvm.org_name;
    abook.hex_srv_start = mvm.hex_srv_start;

    db.SaveChanges();
    MessageBox.Show("Saved");

XAML

<DatePicker x:Name="Txthex_srv_start" SelectedDate="{Binding hex_srv_start}" HorizontalAlignment="Left" Height="26" Margin="10,55,0,0" VerticalAlignment="Top" Width="111" />

If I make any changes to the date, I get the following error:

Error: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. - -2146232032

Any ideas?

2
Contributors
7
Replies
20
Views
3 Years
Discussion Span
Last Post by AndrewDBrown
0

Thanks for helping me out (I'm new to this and still strugling)

Property: hex_srv_start Error: The field hex_srv_start must be a string or array type with a maximum length of '12'.

Edited by AndrewDBrown

0

When you set up EF, did you use Code First or Database First design methods?
It looks like hex_srv_start is the wrong variable type for what you're trying to enter. Is the variable definitely a string type? If so, it may be that you're recording too much data.

Example;
21st Jan 2014 has 13 characters
21/01/2014 00:00:00 has 19 characters

0

It was using "Database first". I have just opened up the MySQL table and it's of type - VARCHAR(12). When I look at egw_addressbook.cs, it has the syntax as: public string hex_srv_start { get; set; }.

Would setting the format of the DatePicker object do the trick (I am only guessing)?

0

It looks like I need to format the DatePicker within the XAML, as the field that I am trying to store the value into wants: YYYY-MM-dd and the DatePicker is providing the format as MM/dd/YYYY 12:00:00 AM.

Any ideas as to how I can convert this within the XAML (if indeed that is where I do it).

1

You can use a Binding Converter to get what you need. It will allow you to do pretty much anything to the data before it is used.

Very useful, very powerful and not too hard to get the hang of :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.