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
 doubt at stored procedures

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2006-10-17 : 02:49:27
hi,
here i am trying write a stored procedure in sql server 2005.i am using this sqlserver2005 is back end to asp.net. i am sending two values from asp.net to this stored procedures. i want to insert this two values into the database. i am sending values as parameters.
in my .net application i had written:
exec dbo.king(" + _id +"," + _id1 +");
in sql server i written stored procedure as

create procedure kingh(@id int,@id1 int)
as
insert into details values(id,id1)
go

but it is showing error as :
The name "id" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.


pls correct my errors in this context.

thanx in advance,
ramu


One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-17 : 02:56:44
exec ('dbo.king ' + @id + ',' + @id1)

But you should really read this topic http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=70783#250380


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-17 : 10:26:50
Isnt it something like this?
Con.Execute('EXEC '+@id+','+@id1)
where con is connection object

Madhivanan

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

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-17 : 10:38:18
The specific error you are seeing is in your stored procedure, it should be

create procedure kingh(@id int,@id1 int)
as
insert into details values(@id, @id1)


You are not using the parameter names (they include the @ at the beginning), that's why SQL Server thinks you are trying to use column names.
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2006-10-17 : 12:10:21
Another thing to note - it looks like a m:m bridge so it might not apply - that you will need to explicitly define the columns to be inserted into if there are more than two in the target table. Personally I do this in any event as a bit of defensive programming but YMMV.
Go to Top of Page
   

- Advertisement -