Solved

calling a stored procedure with argument

Posted on 2012-04-05
5
359 Views
Last Modified: 2012-08-14
hello,

I'm calling my stored procedure and the fact having the first field as an incremental value is causing me trouble.

first field is an INT and setup as IDENTITY. However, in the stored procedure I must specify it and I"m not passing any values to it but then I get an error message as Error converting data type varchar to int.  since my 2nd field being passed to SP is varchar. What is the right approach here?

here is the code:

CREATE PROCEDURE 
add_node (
			@p0 int, 
			@p1  varchar(35), 
			@p2  int, 
			@p3  int, 
			@p4  bit, 
			@p5  varchar(100) 
) as

insert into test(category_Id, name, lft, rgt, visible, description)
values(@p0, @p1, @p2, @p3, @p4, @p5)
go
add_node 'test', 200, 300, 0 ,'some info here ...'   
go
select * from test 

Open in new window


Thanks!
0
Comment
Question by:akohan
5 Comments
 
LVL 5

Expert Comment

by:truinx
ID: 37813760
You are passing string in line 14. 'Test' for @p0 which is int?
0
 
LVL 6

Accepted Solution

by:
yawkey13 earned 100 total points
ID: 37813787
Why must you pass the ID at all?  If it is an identity, it should auto increment.

Eliminate the @p0 param in the sproc def and change your insert statement to:

insert into test(name, lft, rgt, visible, description)
values(@p1, @p2, @p3, @p4, @p5)
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37813860
yawkey is correct.

Then you return the id to your program via:

select scope_identity()
0
 

Author Comment

by:akohan
ID: 37814517
Thanks. I did that yet I'm not sure why I am getting

Invalid object name 'dbo.test'
0
 

Author Comment

by:akohan
ID: 37814561
please ignore my last question. found the issue.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question