Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting values back from Output parameters
Message
From
07/05/2009 11:07:33
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01398353
Message ID:
01398371
Views:
68
This message has been marked as the solution to the initial question of the thread.
I find it much more simplier to generate the GUID of the new record before calling the insert command:
public int InsertNewOrder(OrderDataSet.OrdersRow dr)
{
   OrdersTableAdapter ta = new OrdersTableAdapter();
   dr.OrderPk = Guid.NewGuid();

   return (int)ta.InsertOrderRecord(dr.OrderPk, dr.OrderDate);
}
Are you saying that you have two primary keys? A GUID and a ID? Why?

Always put class that implement IDispose in a "using" block. You will be assured that the class will be disposed correcly.

>I'm wondering if I'm on the right track and how should I modify my code.
>
>In the project I'm working with right now as a sample I see this code
>/// <summary>
>        /// Insert new order
>        ///     returns the newly added key.
>        /// </summary>
>        /// <param name="dr">data row</param>
>        /// <returns>primary key of new record</returns>
>        public int InsertNewOrder(OrderDataSet.OrdersRow dr)
>        {
>            OrdersTableAdapter ta = new OrdersTableAdapter();
>            
>            return (int)ta.InsertOrderRecord(dr.OrderPk, dr.OrderDate);
>        }
>In my case the Orders table has PK as GUID (I want to allow simple merge), ID as Integer Identity and an OrderDate.
>My method in TA is
>SET @NewOrder = NewID();INSERT INTO [Orders] ([OrderPk], [OrderDate]) VALUES (@NewOrder, GetDate()); SET @NewOrderID = Scope_Identity() and both parameters are set to be Output parameters.
>
>So, the question is - how should I pass and how can I get them back in the BL?
>
>BTW, should I call in each method ta.Dispose() to clean up right away or should I switch to using here ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform