views:

888

answers:

3

When trying to add a few items to the database I'm getting this error:

UpdateException was unhandled by user code
An error occurred while updating the entries. See the InnerException for details.

The InnerException contains this:

{"Column count doesn't match value count at row 1"}

I can't see anything wrong with the objects I'm trying to add, all the required values are filled.
Is there any way of viewing the query that causes the problem?

The method's code, if required:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult LaadVerrichtingenIn() {
        int[] intArray = Array.ConvertAll<String, int>(Request.Form["selectedObjects"].Split(','), new Converter<String, int>(Convert.ToInt32));
        List<Verrichting> gekozenVerrichtingen = new List<Verrichting>();

        foreach(int i in intArray){
            base._entities.AddToVerrichtingSet(((Dictionary<int, Verrichting>)Session["ingelezenVerrichtingen"])[i]);
            gekozenVerrichtingen.Add(((Dictionary<int, Verrichting>)Session["ingelezenVerrichtingen"])[i]);
        }
        Session["ingelezenVerrichtingen"] = null;
        base._entities.SaveChanges(); //Exception occurs here

        return View("IngeladenVerrichtingen");
    }

base._entities is an ADO.NET Entity Data Model.

Thanks

+1  A: 

I'm not sure if there's a 'neater' way to do this with the Entity Framework, but if you're using SQL Server then I'd generally use the SQL Server Profiler to read the queries being executed against the server. If you're using a different database then there may be an equivalent - in any case it would probably be helpful if you let us know.

If you're using MySQL > 5.0.37 it has new query profiler functionality - this should be able to show you the queries being sent.

Whisk
Thanks for the answer but unfortunately I'm not using SQL Server.I'm using a MySQL server. I'll look for how I can access the query logs there.
Jeroen Pelgrims
I've updated the answer with a link to the sql profiler in mysql it may help, although it looks like you have to issue the command to enable profiling from the session you want to profile, so you might have to get EF to do that with a manual query. Also see http://stackoverflow.com/questions/20263/is-there-a-profiler-equivalent-for-mysql for other methods.
Whisk
A: 

SQL server profiler will work fine if you're using SQL Server. Within the Entity Framework, you can use the ToTraceString method.

Craig Stuntz
I don't see how I can use that on my code. The examples only show how to use it on queries you wrote yourself. I'm a beginner in the whole .NET framework so I'm probabely overlooking something :)Could you give an example on how I can use that method on the entities variable and extract the quer(y)(ies) that will be executed?
Jeroen Pelgrims
You're right. It is only for selects, not for inserts/updates/deletes.
Craig Stuntz
A: 

I've just come across the same problem while inserting data using the Entity Framework and MySQL. My hunch is, since I'm using double values, that the decimal separator "," is being misinterpreted as a field separator. I upgraded to Connector version 6.1.0, but still no luck. Maybe this is also going on in your case.

Check out this bug report.

BTW, I found that the following line of code works around the problem:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Ton