Solved

"output" var in sql Server

Posted on 2006-10-24
3
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now