Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert Error:

Author  Topic 

Jay123
Yak Posting Veteran

54 Posts

Posted - 2009-12-02 : 08:01:24
Insert Error: Column name or number of supplied values does not match table definition.

i am useing asp.net vb but the code references the sql, thats why im posting here:

SQL = "INSERT INTO Sales.Customer VALUES(@fName,@mName,@lName,@ebayName,@emailAddress);
insert into Sales.customerAddress values(@AddressLine1,@AddressLine2,@AddressLine3,@City,@PostCode,@Country)"



CMD.Parameters.Add("@fName", System.Data.SqlDbType.VarChar, 40).Value = tb_fName.Text.Trim()
CMD.Parameters.Add("@mName", System.Data.SqlDbType.VarChar, 40).Value = tb_mName.Text.Trim()
CMD.Parameters.Add("@LName", System.Data.SqlDbType.VarChar, 40).Value = tb_lName.Text.Trim()
CMD.Parameters.Add("@ebayName", System.Data.SqlDbType.VarChar, 40).Value = tb_eBayName.Text.Trim()
CMD.Parameters.Add("@emailAddress", System.Data.SqlDbType.VarChar, 40).Value = tb_eMailAddress.Text.Trim()

CMD.Parameters.Add("@AddressLine1", System.Data.SqlDbType.VarChar, 50).Value = tb_add1.Text.Trim()
CMD.Parameters.Add("@AddressLine2", System.Data.SqlDbType.VarChar, 50).Value = tb_add2.Text.Trim()
CMD.Parameters.Add("@AddressLine3", System.Data.SqlDbType.VarChar, 50).Value = tb_add3.Text.Trim()
CMD.Parameters.Add("@City", System.Data.SqlDbType.VarChar, 20).Value = tb_city.Text.Trim()
CMD.Parameters.Add("@PostCode", System.Data.SqlDbType.VarChar, 10).Value = tb_postcode.Text.Trim()
CMD.Parameters.Add("@Country", System.Data.SqlDbType.VarChar, 15).Value = tb_country.Text.Trim()


but i have checked and rechecked and as far as i can tell all columns are correct and all values are correct:

here is the table:

CustomerID int Foreign Key(CustomerID) References Sales.Customer,
AddressLine1 varchar(50) not null,
AddressLine2 varchar(50) null,
AddressLine3 varchar(50) null,
City varchar(20) not null,
PostCode varchar(10) not null,
Country varchar(15) not null default 'UK'


Thanks.... .Jay

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-02 : 08:06:47
You need to specify the column names

insert into Sales.customerAddress(list of columns) values(@AddressLine1,@AddressLine2,@AddressLine3,@City,@PostCode,@Country)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -