Click here to Skip to main content
15,895,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a requirenment i have a table of name
 UserOrganisationInfo with columns of 
-->OrgId(bigint PK,identity(1,1))
-->UserId int
-->OrgTypeID int (FOREIGN KEY)
-->Country Id int (FOREIGN KEY)
-->State ID int (FGOREIGN KEY)
-->OrganisationName nvarchar(100)
-->OrganisationLogo nvarchar(max)
-->OrganizationSize bigint
-->City nvarchar(max)
-->Address1 nvarchar(max)
-->Address2 nvarchar(max)
-->Zipcode nvarchar(max)
-->Website nvarchar(max)
-->CreatedOn datetime
-->UpdatedOn datetime
-->Status int
-->OrgDescription nvarchar(max)

In my store procedure i had written all the parameters except for FOREIGN KEY fields...becoz those are belongs to other table..but i am getting the below error...and my store procedure is below..

SQL
create procedure USP_UserOrganizationInfo(
@UserId bigint=null,
@OrganisationName nvarchar(100)=null,
@OrganisationLogo nvarchar(max)=null,
@OrganizationSize bigint=null,
@City nvarchar(max)=null,
@Address1 nvarchar(max)=null,
@Address2 nvarchar(max)=null,
@Zipcode nvarchar(max)=null,
@Website nvarchar(max)=null,
@CreatedOn datetime=null,
@UpdatedOn datetime=null,
@Status int=null,
@OrgDescription nvarchar(max)=null
)
as 
begin
set nocount on 
insert into UserOrganizationInfo values(
@OrganisationName,
@OrganisationLogo,
@OrganizationSize,
@City,
@Address1,
@Address2,
@Zipcode,
@Website,
@CreatedOn,
@UpdatedOn,
@Status,
@OrgDescription)
end


error is-->Column name or number of supplied values does not match table definition.

how do i insert the values of my table except for foreign key fields...any sugestions or advices are broadly accepted.....:)...:)
Posted
Updated 30-Jul-14 0:42am
v2

1 solution

try to write full insert query with column instead of just passing value to query

E.G.

SQL
Insert into TableName (column1,column2,column3) values (@Column1,@Column2,@Column3)
 
Share this answer
 
Comments
Naveen Kumar Malli 30-Jul-14 7:20am    
Thanks..It's working..Nirav....
Nirav Prabtani 30-Jul-14 7:22am    
Welcome.. :)

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