Solved

"output" var in sql Server

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

774 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