[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

"output" var in sql Server

Posted on 2006-10-24
3
Medium Priority
?
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 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