Solved

"output" var in sql Server

Posted on 2006-10-24
3
226 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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

13 Experts available now in Live!

Get 1:1 Help Now