473,809 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

column count does not much value count at row 1

1 New Member
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 2706
RhysW
70 New Member
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
34480
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 advance! We use Oracle 9i.
5
10774
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 message "Column count doesn't match value count at row 1".
2
2261
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 database with those textareas which were changed. Thus, each textarea has an onChange event which marks that box as changed. BUT! Some users report that, if they don't take their cursor out of
4
14081
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
1701
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 give the error but the links does! I get the error on this LINE(when looping):- PageLinks.Text = PageLinks.Text & dtLinks.Rows(iLoop)("link_url")
2
9541
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 interested in, which is "companyID". If instead I use something like: SELECT companyID FROM app;
5
2362
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 PostgresQL is doing a seqscan. I've tried this on a PostgresQL-Serverversion 7.3.4 and 8.0 beta1.
0
4103
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, TYPE VARCHAR(30) NOT NULL, DURATION TIME , YEAR_RELEASE YEAR NOT NULL, DESCRIPTION TEXT,
1
1535
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
48401
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 in memory for later use? DataTable dt = ds.Tables; DataRow foundEmpRows = dt.Select("Dept = 10"); NameValueCollection nvEmp = new NameValueCollection(); foreach (DataRow dr in foundEmpRows) { foreach (DataColumn dc in foundEmpRows)
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.