473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

return value from store procedure

I have this code:

SqlConnection conn = null;
string Table="";

int rCount;

conn = new

SqlConnection(sConn);

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "dbo.[RecepiesSearch]";

cmd.CommandType = CommandType.StoredProcedure;

cmd.Connection = conn;

cmd.Parameters.Add (new SqlParameter ("@Name", tbName.Text ));

cmd.Parameters.Add( new System.Data.SqlClient.SqlParameter("@tbl",
ParameterDirection.Output) );

cmd.ExecuteNonQuery();

imeTablice = cmd.Parameters["@tbl"].Value.ToString();
gridSearch.Grid.DataMember = "";
SqlDataAdapter adap = new SqlDataAdapter();

adap.SelectCommand = cmd;

DataSet ds = new DataSet ();

adap.Fill (ds, Table);

gridSearch.Grid.DataSource = ds;

gridSearch.Grid.DataMember = Table;

this is store procedure:

CREATE PROCEDURE ReceptiSearch
@Name nvarchar(50),
@tbl nvarchar(50) = NULL OUTPUT

AS

if exists
(
select name, ingridients from Cakes where Name = @Name
)
set @tbl='Case'
if exists
(
select name, ingridients from Meat where Name = @Name
)
set @tbl='Meat'

Why doesn't it work?

as the result for Table I get 'OUTPUT'

Hrcko
Dec 9 '05 #1
3 1823
Its because there is no constructor for SqlParameter that accepts the
direction as the second parameter; there *is*, however, one that accepts the
*value* (as an object), which ParameterDirection.Output satisfies - hence
"Output" (the enum) is being used as the parameter value.

Simply use a different constructor, or use the default-constructor and set
the name and direction manually before adding it to the parameters
collection.

Marc

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:dn**********@ss405.t-com.hr...
I have this code:

SqlConnection conn = null;
string Table="";

int rCount;

conn = new

SqlConnection(sConn);

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "dbo.[RecepiesSearch]";

cmd.CommandType = CommandType.StoredProcedure;

cmd.Connection = conn;

cmd.Parameters.Add (new SqlParameter ("@Name", tbName.Text ));

cmd.Parameters.Add( new System.Data.SqlClient.SqlParameter("@tbl",
ParameterDirection.Output) );

cmd.ExecuteNonQuery();

imeTablice = cmd.Parameters["@tbl"].Value.ToString();
gridSearch.Grid.DataMember = "";
SqlDataAdapter adap = new SqlDataAdapter();

adap.SelectCommand = cmd;

DataSet ds = new DataSet ();

adap.Fill (ds, Table);

gridSearch.Grid.DataSource = ds;

gridSearch.Grid.DataMember = Table;

this is store procedure:

CREATE PROCEDURE ReceptiSearch
@Name nvarchar(50),
@tbl nvarchar(50) = NULL OUTPUT

AS

if exists
(
select name, ingridients from Cakes where Name = @Name
)
set @tbl='Case'
if exists
(
select name, ingridients from Meat where Name = @Name
)
set @tbl='Meat'

Why doesn't it work?

as the result for Table I get 'OUTPUT'

Hrcko

Dec 9 '05 #2
I manage to solve a problem with parameter, but now I get an error:

Additional information: Cannot create a child list for field Case.

Why?

Hrcko
"Marc Gravell" <mg******@rm.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
Its because there is no constructor for SqlParameter that accepts the
direction as the second parameter; there *is*, however, one that accepts
the *value* (as an object), which ParameterDirection.Output satisfies -
hence "Output" (the enum) is being used as the parameter value.

Simply use a different constructor, or use the default-constructor and set
the name and direction manually before adding it to the parameters
collection.

Marc

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:dn**********@ss405.t-com.hr...
I have this code:

SqlConnection conn = null;
string Table="";

int rCount;

conn = new

SqlConnection(sConn);

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "dbo.[RecepiesSearch]";

cmd.CommandType = CommandType.StoredProcedure;

cmd.Connection = conn;

cmd.Parameters.Add (new SqlParameter ("@Name", tbName.Text ));

cmd.Parameters.Add( new System.Data.SqlClient.SqlParameter("@tbl",
ParameterDirection.Output) );

cmd.ExecuteNonQuery();

imeTablice = cmd.Parameters["@tbl"].Value.ToString();
gridSearch.Grid.DataMember = "";
SqlDataAdapter adap = new SqlDataAdapter();

adap.SelectCommand = cmd;

DataSet ds = new DataSet ();

adap.Fill (ds, Table);

gridSearch.Grid.DataSource = ds;

gridSearch.Grid.DataMember = Table;

this is store procedure:

CREATE PROCEDURE ReceptiSearch
@Name nvarchar(50),
@tbl nvarchar(50) = NULL OUTPUT

AS

if exists
(
select name, ingridients from Cakes where Name = @Name
)
set @tbl='Case'
if exists
(
select name, ingridients from Meat where Name = @Name
)
set @tbl='Meat'

Why doesn't it work?

as the result for Table I get 'OUTPUT'

Hrcko


Dec 9 '05 #3

"Hrvoje Voda" wrote...
I manage to solve a problem with parameter, but now I get an error:

Additional information: Cannot create a child list for field Case.

Why?


I don't think the code you have provided is the *exact* code that that you
have running, so it's not possible to give a definite answer, but I would
guess that you have misspelled something in your procedure.
if exists
(
select name, ingridients from Cakes where Name = @Name
)
set @tbl='Case'


Shouldn't this be 'Cakes'?

// Bjorn A
Dec 9 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daniel Caetano | last post by:
Hi all, i have a store procedure that i use the return function . Ex. create procedute XX as (statement...) if @@error <> 0 return 1 else return 0 . Inside the vb net i wnat to call that...
1
by: Hugo Lefevre | last post by:
Dear, I have a problem : I have a database which contains my data of hardware. The Id is a varchar and I want at my filling form that my user know which is the last one. So I made a store...
6
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the...
1
by: ken | last post by:
Dear all, question 1: IF (NOT EXISTS(SELECT * FROM table) RETURN 1 ELSE RETURN 0 how to get back the return value from stored procedure from ado.net 2.0 i try Dim result As Boolean =...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
4
by: raghav | last post by:
Hi all I am having a SP which is returning a value......Now I have to store that value in session...I saw some examples in msdn lib ----> string Name=string.Empty; Session=Name.ToString(); ...
8
by: colmkav | last post by:
Can someone tell me how I can access the return value of a function called from Oracle as opposed to a store proc from oracle? my oracle function is get_num_dates_varposfile. I am only used to...
2
by: Mark B | last post by:
I have been able to retrieve the scalar value of a SQL Server Stored Procedure as follows: Shared Function fGetGroupPerformanceStatistic(ByVal strGroup As String) As String Dim sqlConnection1...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.