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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:08:32+00:00 2026-05-28T04:08:32+00:00

I wrote this procedure in a site. it take a string as input parameter(user

  • 0

I wrote this procedure in a site. it take a string as input parameter(user name) and looks into the related table to find out it’s record and return the “ID” field as output of procedure.
this work fine but there’s one (major) problem, which is when it take a input in other English language, it can’t find the target record and return “-1” as output.
The visitors use Persian language and i observed it in my SQLserver. The collation is “Persian_100_CI_AI” and my string fields are “nvarchar”.
what should i do to solve this problem?
i’m using SQL-Server 2008.

thanks a lot

protected int GetThisUserID(string uname)
{
    string returnvalue = "";
    int returnintegervalue = -1;
    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["OldEagleConnectionString"].ToString());
    try
    {
        //SqlCommand command = new SqlCommand("SELECT [ID] FROM [Customers] WHERE ([Uname] = '" + User.Identity.Name.ToString() + "'", connection);
        //SqlCommand command = new SqlCommand("SELECT * FROM [Customers] WHERE ([Uname] = '" + User.Identity.Name.ToString() + "')", connection);
        SqlCommand command = new SqlCommand("SELECT * FROM [Customers] WHERE ([Uname] = '" + uname + "')", connection);

        connection.Open();
        SqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
        {
            while (reader.Read())
            {
                returnvalue = reader["ID"].ToString();

                returnintegervalue = Int32.Parse(returnvalue);
            }
        }
    }
    catch (SqlException ex)
    {
        Response.Write(ex.Message.ToString());
        returnvalue = ex.Message.ToString();
    }
    finally
    {
        connection.Close();
        SqlConnection.ClearPool(connection);
    }
    return returnintegervalue;
}
  • 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-05-28T04:08:33+00:00Added an answer on May 28, 2026 at 4:08 am

    I hate to answer my own question but here it is:

    have to add a N in select command, just like this:

    SqlCommand command = new SqlCommand("SELECT * FROM [Customers] WHERE ([Uname] = N'" + uname + "')", connection);
    

    problem solved!

    Without the N, the string is taken to be a varchar, and the conversion loses characters outside of that supported by the varchar encoding of the database.

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

Sidebar

Related Questions

here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers
Well I have this MySQL stored procedure that I wrote and if I run
I wrote this very simple SP in SQL 2008: Create procedure dbo.GetNextID ( @TableName
I'm extracting data from various sources into one table. In this new table, there's
I write this stored procedure but I am returning all sql queries to site
This is more of a syntax question I'm trying to write a store procedure
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
I wrote this snippet of code and I assume len is tail-recursive, but a
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I wrote this function for filling closed loop, pixvali is declared globally to store

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.