Solved

"output" var in sql Server

Posted on 2006-10-24
3
231 Views
Last Modified: 2010-04-16
I am writing a proceduce in sqlServer:
create proc AddCustomerProc (            
      @FullName nvarchar(100),
      @DateOfBirth datetime,
      @sex bit,
      @Address nvarchar(200),
      @Email varchar(100),
      @Tel char(15),
      @Company nvarchar(200),
      @CountryID char(5),
      @Foreign bit,
      @IDNo char(15),
      @CustomerID char(10)output) as
begin
      --declare @CustomerID char(10)
      declare @temp int
      select @CustomerID=max(Customers.CustomerID) from Customers
      --cat dau
      set @CustomerID= substring(@CustomerID,3,len(@CustomerID)-2)
      set @temp= convert(int,@CustomerID)+1
      set @CustomerID='KH'+convert(char(10),@temp)
      insert into Customers values(
            @CustomerID,
            @FullName,
            @DateofBirth,
            @Sex,
            @Address,
            @Email,
            @Tel,
            @Company,
            @CountryID,
            @Foreign,
            @IDNo)      
end

End then I creates a sqlCommand object in C# language.
sqlCommand.Parameter.Add("@FullName","bucminhqua") ;
the same at others paramater, but i don't known do this with "output @CustomerID" var.
Can you help me?
thank you!
0
Comment
Question by:bucminhqua
3 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 125 total points
ID: 17794276
Hi,

For the output parameter:
sqlCommand.Parameters.Add("@CustomerID", SqlDbType.Char, 10).Direction = ParameterDirection.Output

Once you've executed it, you can then retrieve the value like this:
sqlCommand.Parameters["@CustomerID"].Value
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question