Solved

calling a stored procedure with argument

Posted on 2012-04-05
5
357 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now