Click here to Skip to main content
15,891,473 members
Home / Discussions / Database
   

Database

 
QuestionMore advice on a slighltly more complex select statement Pin
Steven J Jowett12-Sep-08 3:40
Steven J Jowett12-Sep-08 3:40 
AnswerRe: More advice on a slighltly more complex select statement Pin
Ashfield12-Sep-08 4:23
Ashfield12-Sep-08 4:23 
GeneralRe: More advice on a slighltly more complex select statement Pin
Steven J Jowett12-Sep-08 4:45
Steven J Jowett12-Sep-08 4:45 
GeneralRe: More advice on a slighltly more complex select statement Pin
Ashfield12-Sep-08 8:34
Ashfield12-Sep-08 8:34 
QuestionSQL Linked Server/Web Service Question Pin
dhbaer12-Sep-08 3:40
dhbaer12-Sep-08 3:40 
AnswerRe: SQL Linked Server/Web Service Question Pin
Steven J Jowett12-Sep-08 4:05
Steven J Jowett12-Sep-08 4:05 
QuestionAdvice on Select query please Pin
Steven J Jowett12-Sep-08 0:32
Steven J Jowett12-Sep-08 0:32 
AnswerRe: Advice on Select query please Pin
dojohansen12-Sep-08 1:17
dojohansen12-Sep-08 1:17 
Hi,

the exact approach depends on whether you just want to invoke the procedure and check it's return value or if you need to retrieve other results from it as well (a procedure returns an integer with the RETURN statement, but can also return a data set from a SELECT statement or another proc). If you wish to retrieve a dataset returned by the procedure, the simplest approach is to use a data adapter and configure it's SelectCommand to call the procedure. If you only need the return value it's more efficient to use an SqlCommand directly without an adapter.

In any case, you configure the command as follows.

First, set command text and type to specify a proc and it's name:

cmd.CommandText = "myproc"; // name of stored procedure
cmd.CommandType = CommandType.StoredProcedure;

Next, create parameter objects:

SqlParameter name = cmd.Parameters.Add("@name");

If you need the return value from the procedure, add a parameter of type ReturnValue using another Add() overload.

Assign the parameter values according to your logic:

If ...
name.Value = Table1.Name
...
Else
name.Value = Table2.Name
...

Then execute: DataAdapter.Fill() if you're using the adapter, or SqlCommand.ExecuteNonQuery() if you only need the return value. Note that ExecuteNonQuery() returns number of rows affected (in the last batch of the procedure, see @@ROWCOUNT in Sql Server docs), not the return value from the procedure. To get this, read the Value property of the SqlParameter you added.
AnswerRe: Advice on Select query please Pin
Ashfield12-Sep-08 1:39
Ashfield12-Sep-08 1:39 
GeneralRe: Advice on Select query please Pin
Steven J Jowett12-Sep-08 2:18
Steven J Jowett12-Sep-08 2:18 
GeneralRe: Advice on Select query please Pin
Ashfield12-Sep-08 4:16
Ashfield12-Sep-08 4:16 
QuestionSelect Exact Day Pin
Agweet11-Sep-08 22:16
Agweet11-Sep-08 22:16 
AnswerRe: Select Exact Day Pin
dojohansen12-Sep-08 1:21
dojohansen12-Sep-08 1:21 
GeneralRe: Select Exact Day Pin
Agweet12-Sep-08 1:59
Agweet12-Sep-08 1:59 
QuestionNeed some help with deleting process Pin
MarkB77711-Sep-08 22:15
MarkB77711-Sep-08 22:15 
AnswerRe: Need some help with deleting process Pin
Blue_Boy11-Sep-08 22:22
Blue_Boy11-Sep-08 22:22 
GeneralRe: Need some help with deleting process Pin
MarkB77711-Sep-08 23:17
MarkB77711-Sep-08 23:17 
GeneralRe: Need some help with deleting process Pin
Blue_Boy11-Sep-08 23:42
Blue_Boy11-Sep-08 23:42 
GeneralRe: Need some help with deleting process Pin
dojohansen12-Sep-08 1:31
dojohansen12-Sep-08 1:31 
AnswerRe: Need some help with deleting process Pin
razov12-Sep-08 0:11
razov12-Sep-08 0:11 
GeneralRe: Need some help with deleting process Pin
MarkB77712-Sep-08 0:17
MarkB77712-Sep-08 0:17 
GeneralRe: Need some help with deleting process Pin
razov12-Sep-08 0:37
razov12-Sep-08 0:37 
GeneralRe: Need some help with deleting process Pin
MarkB77712-Sep-08 0:44
MarkB77712-Sep-08 0:44 
GeneralRe: Need some help with deleting process Pin
razov12-Sep-08 0:50
razov12-Sep-08 0:50 
AnswerRe: Need some help with deleting process Pin
nelsonpaixao12-Sep-08 14:36
nelsonpaixao12-Sep-08 14:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.