Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8187309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:31:08+00:00 2026-06-07T02:31:08+00:00

I have a webform called UserProfile.aspx . After user logged-in, they can view and

  • 0

I have a webform called UserProfile.aspx. After user logged-in, they can view and edit their particulars at UserProfile. I used a SqlDataSource and was binding the data to a DetailsView. In the details view, it retrieved data from 3 tables and the selecting query works fine and could display data successfully.

However, when I update the information and hit on the Update button in the DetailsView this error appears:

Exception Details: System.Data.SqlClient.SqlException:
Must declare the scalar variable “@UserId”.

Following is the code which I get the current logged-in user(inside UserProfile.aspx):

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>" 

  SelectCommand="SELECT aspnet_Membership.Email, Details.CustName, Details.CustNum, Details.CustRole, Details.CustStatus, Details.PName, Details.PEmail, Details.PRole, Details.WedDate, aspnet_Users.UserName FROM Details INNER JOIN aspnet_Membership ON Details.UserId = aspnet_Membership.UserId INNER JOIN aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId WHERE Details.UserId = @UserId" 
        onselecting="SqlDataSource1_Selecting" 

  UpdateCommand="UPDATE Details SET CustName = @CustName, CustNum = @CustNum, CustRole = @CustRole, CustStatus = @CustStatus, PName = @PName, PEmail = @PEmail, PRole = @PRole, WedDate = @WedDate WHERE [UserId] = @UserId">

        <SelectParameters>
            <asp:Parameter Name="UserId" type="String" />
        </SelectParameters>

EDIT

        <UpdateParameters>
            <asp:Parameter Name="UserId" type="String" />
            <asp:Parameter Name="CustName" type="String"  />
            <asp:Parameter Name="CustNum" type="String" />
            <asp:Parameter Name="CustRole" type="String" />
            <asp:Parameter Name="CustStatus" type="String" />
            <asp:Parameter Name="PName" type="String" />
            <asp:Parameter Name="PEmail" type="String"  />
            <asp:Parameter Name="PRole" type="String"  />
            <asp:Parameter Name="WedDate" type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" 
        AutoGenerateRows="False" 
        DataSourceID="SqlDataSource1" 
        Height="29px" 
        Width="476px">

        <Fields>
            <asp:BoundField DataField="UserName" HeaderText="UserName" 
                SortExpression="UserName" ReadOnly="True" />

            <asp:BoundField DataField="Email" HeaderText="Email" 
                SortExpression="Email" />

            <asp:BoundField DataField="CustName" HeaderText="CustName" 
                SortExpression="CustName" />

            <asp:BoundField DataField="CustNum" HeaderText="CustNum" 
                SortExpression="CustNum" />    

            <asp:BoundField DataField="CustRole" HeaderText="CustRole" 
                SortExpression="CustRole" />
            <asp:BoundField DataField="CustStatus" HeaderText="CustStatus" 
                SortExpression="CustStatus" />
            <asp:BoundField DataField="PName" HeaderText="PName" 
                SortExpression="PName" />
            <asp:BoundField DataField="PEmail" HeaderText="PEmail" 
                SortExpression="PEmail" />
            <asp:BoundField DataField="PRole" HeaderText="PRole" 
                SortExpression="PRole" />
            <asp:BoundField DataField="WedDate" HeaderText="WedDate" 
                SortExpression="WedDate" />
            <asp:CommandField ShowEditButton="True" />

        </Fields>
        <PagerTemplate>
            <br />
        </PagerTemplate>
    </asp:DetailsView>

This is the UserProfile.aspx.cs file:

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    // Get a reference to the currently logged on user
    MembershipUser currentUser = Membership.GetUser();

    // Determine the currently logged on user's UserId value
    // Assign the currently logged on user's UserId to the @UserId parameter
    //access the parameter value using e.Command.Parameters 
    //programmatically set the @UserId:

    e.Command.Parameters["@UserId"].Value = currentUser.ProviderUserKey.ToString();

    Response.Write(currentUser.ProviderUserKey.ToString()); 
    //When I run the webform, the UserId of the current logged-in user had displayed, 
    // the @UserId was not empty. 
}

I was thinking that perhaps the update query could not detect @UserId. But since the @UserId works at the SELECT query, why in the UPDATE, it wasn’t???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:31:09+00:00Added an answer on June 7, 2026 at 2:31 am

    You need to specify UserId as a parameter in the Update parameters as well as Select and Update are two independent commands. The UserId is used in the Update WHERE clause and therefore needs to be supplied.

        <UpdateParameters>
            <asp:Parameter Name="UserId" type="String" />
            <asp:Parameter Name="CustName" type="String"  />
            <asp:Parameter Name="CustNum" type="String" />
            <asp:Parameter Name="CustRole" type="String" />
            <asp:Parameter Name="CustStatus" type="String" />
            <asp:Parameter Name="PName" type="String" />
            <asp:Parameter Name="PEmail" type="String"  />
            <asp:Parameter Name="PRole" type="String"  />
            <asp:Parameter Name="WedDate" type="String" />
        </UpdateParameters>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webform with a a couple of boundfields in an edit window
I have a large webform, and would like to prompt the user to login
I have a mail webform where I have to show the user only (-1)
I have a codeigniter webform, I want to input city/state details from the user,
I have a WebForm before_adm.aspx.cs which has the code as follows: . . .
I have a .Net 4.0 project called BasicTestProject and it contains a webform called
I have a webform and i want to detect if F5 button was pressed
I have a webform with quite a few fields (between 15 to 40, based
I have a WebForm that contains the following definition for the FCKeditor: <FCKeditorV2:FCKeditor ID=txtBody
I have a webform with a PayPal donate button. How do I setup so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.