Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
MySQL server returns an an Error an Error to the visual basic IDE :

MySqlExeception was unhandled : Column count does't match value count at row 1.



This error still occured when a Auto incrementing , nullable column was ommited during the query.
Posted
Comments
Member 9762654 16-Apr-13 7:49am    
can you send the query?
Prasad Khandekar 16-Apr-13 7:49am    
Hello,

The error is self explanatory you are specifying more values than the number of columns. Check the Values part of your SQL and ensure that number of values specified are exactly same as the number of coulmns specified. Please post the code snippet.

The general format of your INSERT query will be

INSERT INTO TABLE_NAME(COL1, COL2, ..., COLN) VALUES(VAL1, VAL2, ..., VALN)

OR If you are using bind parameters

INSERT INTO TABLE_NAME(COL1, COL2, ...COLN) VALUES(?, ?, ...)

So in first case you will have to check the actual values specified in the SQL String and in second case you will have to check number of ?, number of columns and the actual parameters supplied.


Regards,

1 solution

The chances are that your query was of the form:
SQL
INSERT INTO myTable VALUES("Joe", "Bigman" "Smith")
which tries to allocate values on the basis of column numbers: if your auto number field is early in the sequence, one of the given values will be assigned to it - and you will get an error.

Instead of doing that, always name the fields whose values you are supplying:
SQL
INSERT INTO myTable (FirstName, NickNAme, FamilyName) VALUES ("Joe", "Bigman", "Smith")
That way, the database knows exactly which column you are trying to insert a value to, and can use defaults or it's own numbers for the remainder. Plus it's a good idea to list the columns anyway, as it prevents data corruption if the table definition is changed at a later date!
 
Share this answer
 
Comments
compuknow 16-Apr-13 8:33am    
When i pass this command through visual basic , it puts double quotes before Firstname. Like this
"Firstname and MySQL prompts me an error.

I used the visual basic command cmd.ExecuteNonQuery() to execute the MySQL command string.

Thank you.
OriginalGriff 16-Apr-13 9:27am    
Um. You did replace the "FirstName", "NickName" and "FamilyName" values with your own column names, I assume?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900