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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:26:52+00:00 2026-06-16T08:26:52+00:00

I have a problem about SQL Server in my visual studio 2012 web site

  • 0

I have a problem about SQL Server in my visual studio 2012 web site project. For example; I have a table named “user” that has columns “name” ( varchar(16) ) and “surname” ( varchar(16) ). I add new data such as name: “john” surname: “holiday”, but SQL Server automatically fills the rest of the variable with whitespace character. It seems like . How can I block this? I hope I explained my problem clearly.

protected void LoginButton_Click(object sender, EventArgs e)
{
    string connectionString = "Data Source=MYPC-PC\\SQLEXPRESS;Initial Catalog=fff;Integrated Security=True";
    SqlConnection connection = new SqlConnection(connectionString);
    try
    {
        connection.Open();
    }
    catch (Exception s)
    {
        FailureText.Text = s.ToString();
    }
    SqlCommand cmd = new SqlCommand("SELECT * FROM [person] WHERE user_name='" + UserName.Text + "' AND user_password='" + Password.Text + "' ", connection);

    SqlDataReader dr = null;
    dr = cmd.ExecuteReader();

    while (dr.Read())
    {
        if (this.CompareStrings(dr["user_name"].ToString(), UserName.Text) &&
            this.CompareStrings(dr["user_password"].ToString(), Password.Text))
        {
            FailureText.Text = "ok";
        }
        else
        {
            FailureText.Text = "no";
        }


    }
    connection.Close();
    dr.Close();
}

For example when I am debugging “dr[“user_name”]” variable is like that in watch :

  • 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-16T08:26:53+00:00Added an answer on June 16, 2026 at 8:26 am

    this.CompareStrings(dr["user_name"].ToString(), UserName.Text)--> dr["user_name"].ToString().Trim()

    might solve your problem if anyway there are some extra whitespaces

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

Sidebar

Related Questions

I have a Visual Studio 2005 BIDS project that exports about 30 database tables
I have a SQL Server 2008 database and I have a problem with this
I was a MySQL user. Now I'm migrating to SQL Server. But I have
What I have here is this: A Biztalk project in Visual Studio 2010, a
I have some questions about building reports in Report builder 3.0 OR SQL Server
I am using sql server 2008 rc2 and I have a question about naming
I'm struggling with migrating to Visual Studio 2012 Express Edition to handle a project
I have an error message that occurs every time I use SQL Server 2012
I have a problem in SQL Server 2008 Reporting Services. The problem is that
The Problem If I have Visual Studio 2010, Service Pack 1 installed, and I

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.