Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with output parameters and DataSet

Status
Not open for further replies.

m4pv

Programmer
Sep 10, 2004
5
US
Guys,
I'm having a problem trying to populate datatable in dataset with output parameters that return by sql proc.
No errors, just dataset have no tables...

sql proc:
create procedure p_temp
@CODE varchar(4),
@FIRST_NAME varchar (20) output
as
select @FIRST_NAME = 'myName'

c#:
........
SqlDataAdapter oDA = new SqlDataAdapter();
DataSet oDS = new DataSet("INFO");
SqlCommand oCmd = new SqlCommand("p_temp", oConn);
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.Parameters.Add("@CODE", SqlDbType.VarChar, 4, "CODE");
oCmd.Parameters["@CODE"].Value = "1234";
SqlParameter paramOutput = oCmd.Parameters.Add("@FIRST_NAME", SqlDbType.VarChar, 20, "");
paramOutput.Direction = ParameterDirection.Output;
oDA.SelectCommand = oCmd;
oDA.Fill(oDS);
...........
 
In order to use an Output parameter from a SP, you need to use the sqldataadapter's ExecuteNonQuery or ExecuteScalar Method. You are tyring to combine filling a DS and return an Output param, and I don't think it's possible. If you are only returning a single value, use ExecuteScalar.
Also you can just do your select and return the value(s) using the Fill method. I believe you need to pick one or the other.

Jim

 
or rather than returning an output parameter u can use this in ur SP:

remove the @FIRST_NAME as an output parameter and:

delcare @FIRST_NAME varchar (20)
set @FIRST_NAME = 'myName'
select @FIRST_NAME

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top