Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2003, 02:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default ADO .NET return params

Hello,

I have ADO.NET code trying to insert data using a stored procedure to a SQL Server 2000 database. The stored procedure looks like:

Code:
create procedure sp_insertRole
(
  RoleName varchar(100),
  RoleDesc varchar(512) = NULL,
  RoleID   numeric = 0 output
)

as

set nocount on

insert into Role
(
  RoleName,
  RoleDesc
)
values
(
  @RoleName,
  @RoleDesc
)

set @RoleID = @@identity
My code is:

Code:
set objConnection as new SQLConnection(cs)
set objAdapter as new SQLDataAdapter

objAdapter.InsertCommand = new SQLCommand("sp_insertRole", objConnection)
objAdapter.InsertCommand.CommandType = CommandType.StoredProcedure

objAdapter.InsertCommand.Parameters.Add("@RoleName", sqldbtype.varchar).Value = strRoleName
objAdapter.InsertCommand.Parameters.Add("@RoleDesc", sqldbtype.varchar).Value = strRoleDesc

objAdapter.InsertCommand.Parameters.Add(new SQLParameter("@RoleID", sqldbtype.Decimal, 18, ParamDirection.Output))

objConnection.Open()
objAdapter.InsertCommand.ExecuteNonQuery()
intRoleID = objAdapter.InsertCommand.Parameters("@RoleID").Value
objConnection.Close()
When I execute the stored procedure separately in Query Analyzer, it has the correct value, but when I execute it through the ADO.NET code, no value is set (it is set to default of zero in stored proc). Any ideas why the return value is not returning? I've looked at many examples on the web, and they all seem to be doing the same thing I'm doing...

Thanks,

Brian Mains
__________________
Brian
 
Old October 15th, 2003, 03:49 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Something doesn't look right about your sproc create code... this is how I would have pictured it...

create procedure sp_insertRole
(
  @RoleName varchar(100),
  @RoleDesc varchar(512) = NULL,
  @RoleID numeric = 0 output
)


Peter
 
Old October 16th, 2003, 07:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

OK, thanks, the "@" got left out somehow... anyways, even with that problem resolved, I'm still having errors. Anybody know why it won't return a value from the output parameter?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
ADO - function use SQL to return maximal value Humenuk Access VBA 1 June 28th, 2004 04:14 AM
Help Understanding Event default Params nbryson VS.NET 2002/2003 1 January 9th, 2004 12:43 PM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.