473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

column count does not much value count at row 1

Hi guys,
am having trouble with this error code while trying to insert certain values to the database. Can somebody help?

Expand|Select|Wrap|Line Numbers
  1. if (e.ColumnIndex == 4)
  2.                 {
  3.  
  4.                     try{
  5.  
  6.                 string id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
  7.                 string item = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
  8.                 string quantity = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
  9.                 string UnitCost = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
  10.  
  11.                 int quant = int.Parse(quantity);
  12.  
  13.                 double unicost = double.Parse(UnitCost);
  14.                 double tot=quant*unicost;
  15.  
  16.                     try
  17.                     {
  18.                         MySqlConnection connection = new MySqlConnection(Generals.ConnectionString);
  19.                         connection.Open();
  20.                         string sql = "INSERT INTO sales VALUES ('" + id + "','" + item + "','" + quant + "','" + unicost + "','" + DateTime.Now.ToString() + "','"+tot+"')";
  21.                         MySqlCommand cmd = new MySqlCommand(sql, connection);
  22.                         cmd.ExecuteNonQuery();
  23.                         connection.Close();
  24.                         MessageBox.Show("New Sales is added successfully", "Hotel Management", MessageBoxButtons.OK, MessageBoxIcon.Information);
  25.                         this.Refresh();
Mar 30 '12 #1
1 2683
RhysW
70
If ID is set to be an auto incrementing number in the database that could be your problem as it needs the first parameter in the INSERT INTO to be an empty set of quotes '' instead of you manually entering the id, though this is only true if it is an auto-incrementing id.

looking at your code it could well be that you have the database set up to have an auto-incrementing number but youre ignoring it for the use of your own one taken from the table,

perhaps a better explanation of what i am trying to say can be found here

Documentation
Apr 13 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Geetha | last post by:
I searched in the Oracle documents what count (1) meant and I could not find an answer. Can some one explain what Oracle does internally when use count (1) VS count (*). Thank you very much in...
5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
2
by: S Wickes | last post by:
I've become suspicious that the submit button does not count as an onChange event in some browsers. Here's why. I have a form with many textareas. After you click submit, I only update the...
4
by: Laszlo Csabi | last post by:
Hi Folks, Can someone explain me why I'm getting the following error? The error message I got is : "Parameter count does not match Parameter Value count."
7
by: Patrick Olurotimi Ige | last post by:
I have a simple Stored Procedure with multiple select statements..doing select * from links for example. I created a DataTable and then fill the tables But the first dtTemplate DataTable doesn't...
2
by: Iker Arizmendi | last post by:
Using psql and running as the owner of the table "app" I try to access the columns of the table like so: SELECT * FROM app; which returns all the columns in the table including the one I'm...
5
by: Silvio Matthes | last post by:
Hello, I'm new to the list and did not find a suitable answer to my question so here it is: I try to select the rows of a table where the content of a varchar-column is empty ('') and...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
1
by: Nellorekrishna | last post by:
Hi , Can anybody help in in finding count of value in a column. suppose test is a column and in it value are seperated by comma (''krishna","vijay",.......)
1
by: Sri13 | last post by:
Hi I have a DataTable and get selected values out of it in a DataRow collection. I have the code that I want to make it run. Not sure if this is the correct approach to store column names and value...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.