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

Database

 
QuestionCounting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 3:25
Sunset Towers2-Aug-07 3:25 
AnswerRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 3:29
kubben2-Aug-07 3:29 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 3:37
Sunset Towers2-Aug-07 3:37 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 5:10
Sunset Towers2-Aug-07 5:10 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 5:22
kubben2-Aug-07 5:22 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 5:43
kubben2-Aug-07 5:43 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 6:01
Sunset Towers2-Aug-07 6:01 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 6:29
kubben2-Aug-07 6:29 
Ok, there are several ways of doing it. I would guess the easiest is to just return an output parameters. so your SP looks like:
CREATE PROCEDURE dbo.StoredProcedure1 
  @param1 int,
  @cnt int output
as
Select @cnt = count(*) from TABLE where column = @param1
RETURN 0
<pre>

So then when you call the stored procedure you will have to add two sqlparameters to your sqlcommand.  The @cnt needs to be marked as direction = output

After you call to executenonquery on the stored procedure you can then check the parameters and get the output value.  Then use this value when doing the insert or update.

You can't actually call a stored procedure in an insert statement.  
You can call a function, but there are other limitation with functions.

Hope that helps.
Ben

GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 7:18
Sunset Towers2-Aug-07 7:18 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 7:20
kubben2-Aug-07 7:20 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 7:22
Sunset Towers2-Aug-07 7:22 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 7:25
kubben2-Aug-07 7:25 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 7:37
Sunset Towers2-Aug-07 7:37 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 7:51
kubben2-Aug-07 7:51 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 8:24
Sunset Towers2-Aug-07 8:24 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 8:28
kubben2-Aug-07 8:28 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
Sunset Towers2-Aug-07 9:35
Sunset Towers2-Aug-07 9:35 
GeneralRe: Counting the Records in a Database for a Insert Statement Pin
kubben2-Aug-07 13:15
kubben2-Aug-07 13:15 
QuestionTransaction in dotNET and SqlServer Pin
Developer6112-Aug-07 1:28
Developer6112-Aug-07 1:28 
AnswerRe: Transaction in dotNET and SqlServer Pin
Colin Angus Mackay2-Aug-07 1:38
Colin Angus Mackay2-Aug-07 1:38 
QuestionRe: Transaction in dotNET and SqlServer Pin
Developer6112-Aug-07 1:56
Developer6112-Aug-07 1:56 
AnswerRe: Transaction in dotNET and SqlServer Pin
Colin Angus Mackay2-Aug-07 7:50
Colin Angus Mackay2-Aug-07 7:50 
QuestionRe: Transaction in dotNET and SqlServer Pin
SalarSoft3-Aug-07 21:50
SalarSoft3-Aug-07 21:50 
AnswerRe: Transaction in dotNET and SqlServer Pin
Colin Angus Mackay3-Aug-07 22:10
Colin Angus Mackay3-Aug-07 22:10 
Questionhow to get the exact year and month Pin
neo_bags2-Aug-07 0:58
neo_bags2-Aug-07 0:58 

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.