Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
when i am enter values in textboxes store in database. if not equal fields and textboxes how to insert values in database

i got this error

Column name or number of supplied values does not match table definition.
SQL
USE [Incometax]
GO
Posted
Updated 16-May-12 15:41pm
v4

Change your INSERT statement with something like this:
SQL
INSERT INTO other_source_income (Field1, Field2,... Field11) VALUES (Value1, Value2,... Value11)
 
Share this answer
 
Comments
VJ Reddy 16-May-12 7:20am    
My 5!
Maciej Los 16-May-12 7:29am    
Thank you ;)
fjdiewornncalwe 16-May-12 16:52pm    
Of Course. +5.
Maciej Los 16-May-12 17:08pm    
Thank you ;)
You need to specify the fields of the values you want to insert on your statement if you are not inserting values to all of them. Since you haven't provided the fields, it assumes that you want to insert to all of them, hence the error. An example of how to do it would be
SQL
INSERT INTO Table1 (column1, column2) VALUES ('value1','value2')


Also, the way you're constructing your query is dangerous, as its open to SQL injection attacks. Use SqlParameter[^] instead of concatenating values to your query.
 
Share this answer
 
Comments
VJ Reddy 16-May-12 7:21am    
My 5!
walterhevedeich 16-May-12 21:36pm    
Thanks.
Maciej Los 16-May-12 7:30am    
Good answer, my 5!
walterhevedeich 16-May-12 21:36pm    
Thanks
fjdiewornncalwe 16-May-12 16:52pm    
+5. Of Course.
Make a good practice of passing the fields and values in insert query like

SQL
insert into tablename (field1,field2,field3,.....,fieldn) values(value1,value2,value3,.....,valuen)


instead of using
//bad practice
SQL
insert into tablename values(value1,value2,value3,.....,valuen)


better to use procedure for insert query.
 
Share this answer
 
Comments
Maciej Los 17-May-12 6:19am    
Good answer, my 5!
AshishChaudha 17-May-12 6:24am    
Thanks!!
You need insert value into database use textbox text,

first you verified database table value fields datatype(int or float or char)

SQL
[osi_no] [int] IDENTITY(1,1) NOT NULL
, this is datatype is int.

so you could not insert textbox text because text for datatype is string,
so you convert to implicit or explicit.

example
C#
+ int.Parse(txtOSITDSFromBank.Text) 

or
C#
converto.Int32(txtOSITDSFromBank.Text)
 
Share this answer
 
v2

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