How to get the value of the variable in SqlDataSource  control?

Posted on 2009-02-15
Last Modified: 2012-05-06
Hi, please consider the following SqlDataSource control, I defined the output variable NewUser_ID, now where I can get its value in the code behind?
<asp:SqlDataSource ID="InsertAgent_SqlDataSource"  ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 

            InsertCommand="INSERT INTO [User]([name], [Password], Full_Name,  Email,   IsDisabled, [Description], Date_Created, Date_PasswordModified, LoginCount, IsPasswordExpired, IsPasswordChangeable, MustChangePassword) 

                            VALUES (@username, @password, @firstname, @email, 0, @Description,GETDATE(), GETDATE(), 0, 0, 0, 0);SELECT @NewUser_ID = SCOPE_IDENTITY();

                            INSERT INTO [Path]([name], [Path_Location], [Description], Date_Created) 

                            VALUES (@name, @location, @PathDescription, GETDATE()); SELECT @NewPath_ID = SCOPE_IDENTITY();

                            INSERT INTO [Permission]([User_FK], [Path_FK], [Quota_Unlimited], [Traverse], [Create], [Delete], [Rename],[edit], [upload], [download], [compress], [cut], [copy], [paste],[listcontent],[extract]) 

                            VALUES (@NewUser_ID, @NewPath_ID, 1, 1,1,1,1,1,1,1,1,1,1,1,1, 1); " runat="server">


                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtUsername" Type="String" Name="username"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtPassword" Name="password"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtFirstName" Name="firstname"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtEmail" Name="email"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtDescription" Name="Description"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtPathName" Type="String" Name="name"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtPathLocation" Name="location"  />

                    <asp:ControlParameter ControlID="frmvwAgentAdd$txtPathDescription" Name="PathDescription"  />

                    <asp:Parameter Direction="Output"  Name="NewUser_ID"  />

                    <asp:Parameter  Name="NewPath_ID"  />


Open in new window

Question by:Abdu_Allah
    LVL 16

    Expert Comment

    LVL 16

    Expert Comment

    LVL 15

    Accepted Solution

    It's pretty simple, just intercept the "InsertAgent_SqlDataSource_Inserted" function.

      Protected Sub InsertAgent_SqlDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted
       Dim s as String = e.Command.Parameters("@NewUser_ID").Value
       'Do something with new ID
    End Sub

    Open in new window


    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now