如何使用我的商店程序插入值 [英] How do I Insert values with my Store Procedures
本文介绍了如何使用我的商店程序插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在要求中,我有一个名为
UserOrganisationInfo 的表,其中列为
- > OrgId(bigint PK,identity(1,1))
- > UserId int
- > OrgTypeID int(FOREIGN KEY)
- > 国家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)
- >网站nvarchar(max)
- > CreatedOn datetime
- > UpdatedOn datetime
- - > Status int
- > OrgDescription nvarchar(max)
在我的商店程序中,我写了除FOREIGN KEY字段以外的所有参数。 .becoz那些属于其他表..但我得到以下错误...我的商店程序在下面..
创建 < span class =code-keyword> procedure USP_UserOrganizationInfo(
@ UserId bigint = null,
@ OrganisationName nvarchar ( 100 )= null,
< span class =code-sdkkeyword> @ 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
设置 nocount
插入 进入 UserOrganizationInfo 值(
@ OrganisationName ,
@ OrganisationLogo ,
@ OrganizationSize ,
@ City ,
@ Address1 ,
@ Address2 ,
@ Zipcode ,
@ Website ,
@ CreatedOn ,
@ UpdatedOn ,
@ Status ,
@ OrgDescription )
end
错误是 - >列名或提供的值数与表定义不匹配。
我如何插入我的表的值,除了外键字段...任何sugestions或建议被广泛接受..... :) ... :):
解决方案
尝试使用列编写完整的插入查询,而不是仅仅将值传递给查询
EG
将 插入 TableName (column1,column2,column3) values ( @ Column1 , @ Column2 , @ Column3 )
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..
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.....:)...:)
解决方案
try to write full insert query with column instead of just passing value to query
E.G.
Insert into TableName (column1,column2,column3) values (@Column1,@Column2,@Column3)
这篇关于如何使用我的商店程序插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文