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 8563661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:00:40+00:00 2026-06-11T17:00:40+00:00

I have used an sql statement where I want to display the details of

  • 0

I have used an sql statement where I want to display the details of the current user that is logged in. But when I run this command it

ConnectionString = "<%$ ConnectionStrings:Details %>" 

SelectCommand = "SELECT *  FROM member WHERE username = 'User.Identity.Name'"

it does not show any details but when I run

SelectCommand = "SELECT *  FROM member WHERE username = 'david'" 

the username david exists in the database and displays the details of only david in the web form. I even did Response.Write on the User.Identity.Name and that statement displays the current user that is logged in the page.

  • 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-11T17:00:41+00:00Added an answer on June 11, 2026 at 5:00 pm

    The issue is you’re passing the actual User.Identity.Name as string instead of its value.

    SelectCommand = String.Format("SELECT *  FROM member WHERE username = '{0}'", User.Identity.Name)
    

    But the better (and safer) practice would be something like

    SelectCommand = "SELECT *  FROM member WHERE username = @UserName"
    SelectCommand.Parameters.AddWithValue("@UserName", User.Identity.Name)
    

    This will prevent SQL injection.

    EDIT:
    Since you are defining this in your page, you can use the following template:

    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:Details %>" SelectCommand="SELECT * FROM members WHERE ([username] = @UserName)">
        <SelectParameters>
            <asp:Parameter Name="UserName" Type="String" DefaultValue="" />
        </SelectParameters>
    </asp:SqlDataSource>
    

    Then set the default value to User.Identity.Name on the server side:

    SqlDataSource1.SelectParameters.Item(0).DefaultValue = User.Identity.Name
    

    The easier way to do this is by using the Configure Data Source wizard, which is available by clicking the right arrow beside the SqlDataSource object in design view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have SQL query statement which used to display the contents in the table.
I have a column in my SQL-2005 database that used to be a varchar(max)
I have a class containing Linq To SQL objects that are used to populate
Can someone help me with this SQL statement. I run it on the SQL
This is likely very easy, I haven't used sql in a while and have
I have an SQL server database that I am querying and I only want
I have used COALESCE numerous times but I suppose I never encountered this particular
I have used SQL SERVER 2005 & c# .net for front end & app.config
We have SQL Server 2008 R2 and Visual Studio 2008. I have used the
I have seen prefix N in some insert T-SQL queries. Many people have used

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.