Call stored procedure with paremeter output in c#

Hi,
I have the next stored procedure in Sql Server 2008:

CREATE PROCEDURE [dbo].[GetNumTiquet]
@IdEmpresa int,
@NumTiquet int OUTPUT
AS
BEGIN
	SET NOCOUNT ON;

	UPDATE ConfGen
	SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
	WHERE Id = @IdEmpresa
END

If i execute this stored procedure with Sql Server 2008 all is ok.
But how can i call this stored procedure with c#?

Thanks
0
Paul
7/1/2010 3:39:46 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

5 Replies
1711 Views

Similar Articles

[PageSpeed] 22

Paul wrote:
> Hi,
> I have the next stored procedure in Sql Server 2008:
> 
> CREATE PROCEDURE [dbo].[GetNumTiquet]
> @IdEmpresa int,
> @NumTiquet int OUTPUT
> AS
> BEGIN
> 	SET NOCOUNT ON;
> 
> 	UPDATE ConfGen
> 	SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> 	WHERE Id = @IdEmpresa
> END
> 
> If i execute this stored procedure with Sql Server 2008 all is ok.
> But how can i call this stored procedure with c#?
> 
> Thanks

<http://www.google.com/#hl=en&q=how+to+get+output+parameter+from+stored+procedure+ado.net&aq=f&aqi=&aql=&oq=how+to+get+output+parameter+from+stored+procedure+ado.net&gs_rfai=&fp=c0cfdbfb1e48170b>
0
Mr
7/1/2010 6:18:36 PM
On 01-07-2010 11:39, Paul wrote:
> I have the next stored procedure in Sql Server 2008:
>
> CREATE PROCEDURE [dbo].[GetNumTiquet]
> @IdEmpresa int,
> @NumTiquet int OUTPUT
> AS
> BEGIN
> 	SET NOCOUNT ON;
>
> 	UPDATE ConfGen
> 	SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> 	WHERE Id = @IdEmpresa
> END
>
> If i execute this stored procedure with Sql Server 2008 all is ok.
> But how can i call this stored procedure with c#?

Something like (untested):

SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
cmd.Parameters.Add(prm1);
SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
prm2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm2);
cmd.Parameters["@IdEmpresa"].Value = v;
cmd.ExecuteNonQuuery();
int res = (int)cmd.Parameters["@NumTiquet"].Value);

Arne
0
ISO
7/1/2010 9:52:58 PM
On 01-07-2010 17:52, Arne Vajh�j wrote:
> On 01-07-2010 11:39, Paul wrote:
>> I have the next stored procedure in Sql Server 2008:
>>
>> CREATE PROCEDURE [dbo].[GetNumTiquet]
>> @IdEmpresa int,
>> @NumTiquet int OUTPUT
>> AS
>> BEGIN
>> SET NOCOUNT ON;
>>
>> UPDATE ConfGen
>> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
>> WHERE Id = @IdEmpresa
>> END
>>
>> If i execute this stored procedure with Sql Server 2008 all is ok.
>> But how can i call this stored procedure with c#?
>
> Something like (untested):
>
> SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
> cmd.CommandType = CommandType.StoredProcedure;
> SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
> cmd.Parameters.Add(prm1);
> SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
> prm2.Direction = ParameterDirection.Output;
> cmd.Parameters.Add(prm2);
> cmd.Parameters["@IdEmpresa"].Value = v;
> cmd.ExecuteNonQuuery();
> int res = (int)cmd.Parameters["@NumTiquet"].Value);

Note that the use of:

SELECT MAX()+1

usually is the wrong approach and instead SCOPE_IDENTITY() should
be used in the following SQL statements.

Arne
0
ISO
7/1/2010 9:54:02 PM
On 1 jul, 23:54, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
> On 01-07-2010 17:52, Arne Vajh j wrote:
>
>
>
>
>
> > On 01-07-2010 11:39, Paul wrote:
> >> I have the next stored procedure in Sql Server 2008:
>
> >> CREATE PROCEDURE [dbo].[GetNumTiquet]
> >> @IdEmpresa int,
> >> @NumTiquet int OUTPUT
> >> AS
> >> BEGIN
> >> SET NOCOUNT ON;
>
> >> UPDATE ConfGen
> >> SET @NumTiquet=3DNumTiquet =3D (SELECT MAX(NumTiquet) +1 FROM ConfGen)
> >> WHERE Id =3D @IdEmpresa
> >> END
>
> >> If i execute this stored procedure with Sql Server 2008 all is ok.
> >> But how can i call this stored procedure with c#?
>
> > Something like (untested):
>
> > SqlCommand cmd =3D new SqlCommand("dbo.GetNumTiquet", con);
> > cmd.CommandType =3D CommandType.StoredProcedure;
> > SqlParameter prm1 =3D new SqlParameter("@IdEmpresa", SqlDbType.Int);
> > cmd.Parameters.Add(prm1);
> > SqlParameter prm2 =3D new SqlParameter("@NumTiquet", SqlDbType.Int);
> > prm2.Direction =3D ParameterDirection.Output;
> > cmd.Parameters.Add(prm2);
> > cmd.Parameters["@IdEmpresa"].Value =3D v;
> > cmd.ExecuteNonQuuery();
> > int res =3D (int)cmd.Parameters["@NumTiquet"].Value);
>
> Note that the use of:
>
> SELECT MAX()+1
>
> usually is the wrong approach and instead SCOPE_IDENTITY() should
> be used in the following SQL statements.
>
> Arne- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Hi,
I don't understant.
What do you menan with SCOPE_INDENTITY() with this example?
Thanks
0
Paul
7/2/2010 9:22:11 AM
Paul wrote:
> On 1 jul, 23:54, Arne Vajh�j <a...@vajhoej.dk> wrote:
>> On 01-07-2010 17:52, Arne Vajh j wrote:
>>
>>
>>
>>
>>
>>> On 01-07-2010 11:39, Paul wrote:
>>>> I have the next stored procedure in Sql Server 2008:
>>>> CREATE PROCEDURE [dbo].[GetNumTiquet]
>>>> @IdEmpresa int,
>>>> @NumTiquet int OUTPUT
>>>> AS
>>>> BEGIN
>>>> SET NOCOUNT ON;
>>>> UPDATE ConfGen
>>>> SET @NumTiquet=NumTiquet = (SELECT MAX(NumTiquet) +1 FROM ConfGen)
>>>> WHERE Id = @IdEmpresa
>>>> END
>>>> If i execute this stored procedure with Sql Server 2008 all is ok.
>>>> But how can i call this stored procedure with c#?
>>> Something like (untested):
>>> SqlCommand cmd = new SqlCommand("dbo.GetNumTiquet", con);
>>> cmd.CommandType = CommandType.StoredProcedure;
>>> SqlParameter prm1 = new SqlParameter("@IdEmpresa", SqlDbType.Int);
>>> cmd.Parameters.Add(prm1);
>>> SqlParameter prm2 = new SqlParameter("@NumTiquet", SqlDbType.Int);
>>> prm2.Direction = ParameterDirection.Output;
>>> cmd.Parameters.Add(prm2);
>>> cmd.Parameters["@IdEmpresa"].Value = v;
>>> cmd.ExecuteNonQuuery();
>>> int res = (int)cmd.Parameters["@NumTiquet"].Value);
>> Note that the use of:
>>
>> SELECT MAX()+1
>>
>> usually is the wrong approach and instead SCOPE_IDENTITY() should
>> be used in the following SQL statements.
>>
>> Arne- Ocultar texto de la cita -
>>
>> - Mostrar texto de la cita -
> 
> Hi,
> I don't understant.
> What do you menan with SCOPE_INDENTITY() with this example?
> Thanks

If the key of the record was using Identity Incremental on the 
primary-key to the record, an int field type, then when a new record is 
inserted the incremental int key is assigned to the inserted record. The 
Scope_Identity allows one to get the key of the record inserted at the 
time of record insertion.

This allows you to pass the Identity key to be passed as output from the 
sproc back to the C# program so it can use in other C# code processing, 
like retrieve the record by its just inserted record-key ID as an example.


0
Mr
7/2/2010 11:14:05 AM
Reply:

Similar Artilces:

Phone calls from my modem
I've asked this question before but have lost the answer. On my last phone bill, i was charged for two calls to Chile which I queried with BT. They tell me that the number is a data line which has been accessed from my modem using international dialling which terminates the call to my ISP and connects via the international number. How do i protect against this happening again? Many thanks ...

Outlook folders not saved in users Exchange mailbox store
I am the admin and I can see that my other users have log on time, number and size of messages, and log of time. I have one user that has log on and off times but no number and size of messages. Is it possible for a user to configure their account to hide this information? On Tue, 27 Mar 2007 19:00:56 -0700, jimsmith <jimsmith@discussions.microsoft.com> wrote: >I am the admin and I can see that my other users have log on time, number and >size of messages, and log of time. I have one user that has log on and off >times but no number and size of messages. Is it possibl...

How do I calculate and store results? 01-27-10
I have a Form with a QTY field and a field AMOUNT_TAKEN. I need to have the AMOUNT_TAKEN subtracted from QTY when I click on a Calculate Button and also have the AMOUNT_TAKEN field cleared. How do I do the update of the QTY with a query and store it for further use? I have a Table with both QTY and AMOUNT_TAKEN fields Thanks! Joe Leon - Bring up the Properties for the form. Set the RecordSource to be the table that contains your data. For each of the two fields on the form, make sure the Control Source property is the associated field from the table. This will take ca...

Integrate Ericsson Call Center Client into Microsoft CRM 3.0
Hi! the call center client application have API in COM Object (build in C++), all the call features and fucntion can call from the API, i have no idea's on how to integrate this com object into the CRM Client so that when have an incoming service call, the CRM client will pop up the call case window and the user also able to answer or hang up the call from the CRM client interface. i have study the CRM SDK but still can find the solution. Appriciate can give me some clues to start. Thanks! ...

static object destructor not getting called
hi I have a static object in a file. For some reasons its destructor is not getting called, this object is supposed to free up the memory, and because of the destructor not getting called , visual studio reports all of them as memory leaks. I am using VS 2005. Any suggestions? Regards Chimanrao On 20 May 2007 21:12:50 -0700, Chimanrao <chimanrao@gmail.com> wrote: >I have a static object in a file. >For some reasons its destructor is not getting called, It seems strange. Static objects are deleted (so the destructor is called) when global variables are deallocated, so when t...

Best POS/Inventory System for Grocery Store
Hi All, I was wondering what in your opinioin is the best POS/Inventory system out there. And how does RMS rank up? Thank you ...

Who could tell me about LPC(Local Procedure Call) and provide some examples?
Hello all: Who could give me some documents about LPC(Local Procedure Call) and provide some examples?There are examples on server and client.Thanks very muvh. ...

Phone Call
Is there are way to change the Call Initiator on a batch of phone call activities? When Leads are reassigned the activities are reassigned but the Call Initiator field remains set to value of the phone call creator. ...

Excel, Can the letter A B C on the columbs heading be changed?
Excel 2003 I want to put a woud were the columb letter is. can this be done You can put a word in Row 1 and leave the column letters alone. (You can actually hide the column letters and row numbers under tools|options|View tab, if you really want.) Paul fxb wrote: > > Excel 2003 I want to put a woud were the columb letter is. can this be done -- Dave Peterson Hi > (You can actually hide the column letters and row numbers under > tools|options|View tab, if you really want.) And then you can select A2 then and use Window>Freeze panes to freeze your new header -- Rega...

output date modified if data is entered for multiple rows
Hello, I'm currently creating an excel programin which i want to create some vb code that will check to see if a particular row's (from C to AA) cell has been modified and to then output that modification date to the corresponding row's AB cell. So for instance...if someone modifies the cell H7...then the modification date would be outputted to AB7. I have approximately 100 rows of data that needs this to be done for, and I can get the code to work for an individual row, but I cant figure out how to have it check all the rows in my spreadsheet and output it to the corresponding ro...

Invalid stored procedure error while trying to create a store in H
Hello, I have a store installation which includes headquarters. I was creating a store and I get an error with the message 'Invalid Stored Procedure'. I had already created 1 store and had no problems. Has anybody seen this problem? Any work around? ...

Covered calls etc.
Have they taught Money to handle downloads from your broker of items like covered calls and bull-put spreads etc. etc.? In microsoft.public.money, az-willie wrote: >Have they taught Money to handle downloads from your broker of items >like covered calls and bull-put spreads etc. etc.? No. Cal Learner-- MVP wrote: >In microsoft.public.money, az-willie wrote: > > > >>Have they taught Money to handle downloads from your broker of items >>like covered calls and bull-put spreads etc. etc.? >> >> > >No. > > ======= Quicken 2004 d...

Telephone number for Telefonica Windows Live Call
Hi. Having trouble adding minutes to my account. Anyone have a phone number or e-mail for either Telefonica or Windows Live Call that I can contact for help? Thanks! Greetings, Supposedly, if you head over to: http://support.live.us.telefonica.com/?Country=US&Language=en Choose Payment and Balance Problems on the side, and then choose one of the "problems" listed, then choose " If you are still having trouble after the above steps, please Click Here ", you'll reach a form to assist. -- Jonathan Kay Microsoft MVP - Windows Live Messenger MSN Mes...

Please add delete action to IMF for information store
Can *anyone* in the Microsoft Exchange team respond to this: Please can the option to *delete* messages be added to the IMF actions for an information store? Why would we want to do this? We are a K12 school and have two Information stores, one for staff, one for students. It is quite acceptable to deliver spam into the junk email folder for staff. It is *not* acceptable to do this for students. Even though the UCE level is getting set correctly (ie the message is correctly classified as spam) the inability to *delete* such messages from the student information store results in adult m...

Centralize in C++
Hello! How I centralize in C++? ex: My name is Sonia. Thanks for your help. ...

Call in?
Do new owners of Office X have to call up Microsoft to register their copy? If yes, what's the number? thanks. Ming <asdf@asdf.com> wrote: > Do new owners of Office X have to call up Microsoft to register their > copy? If yes, what's the number? thanks. Nope. We're not using Windoze :->>> This version does not require activation. Corentin -- - Mac:MS MVP (Francophone) - (MS) MVP: http://support.microsoft.com/default.aspx?ln=FR&scid=fh;FR;mvp Newsgroups produits MS: http://support.microsoft.com/newsgroups/?ln=FR ...

Link error in C++ COM projet
We have an exsting C++ COM project in Visual studio 7, actually this project was original built with VC6, and built with VC7. Some idspatch interfces are alreday there and works fine (no problem in compile and link). Now I need to add a new interface into this project. I am using the VC7 IDE to add ATL simple class, it is just an empty interface, no property and method, then build it, link errors come: LNK2001: unresolved external symbol _hProxyDll LNK2019: unresolved external symbol _PrxDllCanUnloadNow@0 referenced in function _DllCanUnloadNow@0 LNK2019: unresolved external symbol _Pr...

IMF not filtering just one Xchange store
Hi, I am running Exchange 2003 SBS edition SP2. Just recently my Junk Folder (out of 10) has stopped filtering Spam. I am running in cached mode and IMF is enabled. The other 9 people on this exchange server seem to be unaffected. I really haven't updated or changed anything locally; however I did just do the SBS SP2 update which included an Exchange update but I was already running SP2 on exchange so it skipped that update. Any thoughts? - Is mail for other recipients being filtered? (Assuming yes... ) - Try exposing SCL values in Outlook - are *any* internet messages getting SCL v...

Calling a webservice with parameter from contacts
Hi, I would like to call a webservice when i am in a contact form (I made an icon in the left bar to launch it) ; my problem is to get an information from the form to be verified in the webservice : how can i pass the parameters? (I am not yet a great developper in .net...) Thanks for your help this line of course in C# will get you the id of the object calling the code string id=Request.Params["oId"]; -- John O'Donnell Microsoft CRM MVP http://www.microsoft.com/BusinessSolutions/Community/CRMFaqLanding.aspx "B. Guillout" <BGuillout@discussions.microsoft.com&...

Initiate Phone Calls from CRM
Anyone know of an add-on that will enable CRM clients (browsers or SFO ideally) to click on a phone number or link button to initiate a phone call via a modem in local user's computer? Several clients ask for this - esp. whe nthey are dealing with long (international) numbers. Thanks Roger On Fri, 19 Aug 2005 09:22:32 +0100, "Roger" <roger_id@hotmail.com> wrote: >Anyone know of an add-on that will enable CRM clients (browsers or SFO >ideally) to click on a phone number or link button to initiate a phone call >via a modem in local user's computer? &...

Passing value back to calling form (cntl) from popup
Hi all, I have a form that contains order info with subform (datasheet view) that contains order detail. In the itemname combo box of the subform the user can select the item name. The combo box rowsource is the itemsQ and the Control source is the ordersDtlQ (itemname) field. I have a field in itemsQ query called subcat which is a subcategory field . Here is what I am trying to do. When the user enters a new item in the table user can decide to make item a sub categoring of another record. The default subcat is the itemid if no subcat is assigned. Lets say the user selects "wrench"...

FRX Report Launcher Error: 5 Invalid procedure call or argument
I am currently having an issue with receiving an error message when attempting to launch FRX Report Launcher. Error: 5 Invalid procedure call or argument. followed by OK FRx launcher will not Launch. I am able to launch FRx designer, and Drilldown viewer, just not launcher. The version of frx is 6.7.7032. We work in a citrix environment pointing back to a SQL server for Great Plains and FRx data. Any assistance would be appreciated as this is month end. -- Bonnie Pitchford Systems Accounting Manager Mercury Companies, Inc. There are multiple possibilities for an Error 5 Invalid p...

Errors trying to move mailboxes between mail stores #2
Hi, We have four mailbox on an Exchange 2003 server. I am trying to move certain individuals mailboxes from one store to another (on the same server) to keep the mailboxes more organised. The move process works for 99% of our mailboxes, however, a certain few fail to move using the Move Wizard. They can be moved from say the 1st mail store to the 3rd, but not to the second! However, other mailboxes currently in the second mail store will move to othere stores without issue!! When a move fails, the error we get is: "After moving a mailbox, you must wait for cleanup operations to co...

Does anyone have a call log to track calls?
We need to create a call log that would include date received, caller's name, address, phone number, type of problem/complaint, department that handled, date completed. We would like to be able to analyze the types of calls received and how efficiently they are handled. ...

What table are Credit Memos stored on?
On what table can Credit Memos be found? I've been looking everywhere, and I can't find them for some reason... Thanks, Jeremy Are you using SOP? It would be SOP10100/10200 for open and SOP30200/30300 for historical For RM credit memos. Look for the invoice work, open, and historical tables. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com "Jeremy Harrington" wrote: > On what table can Credit Memos be found? I've ...