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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:11:50+00:00 2026-06-04T01:11:50+00:00

I have created asp.net WebService. I want to update user’s info after validating him

  • 0

I have created asp.net WebService. I want to update user’s info after validating him , means if new UserName entered by him is not already exist than only he can update new UserName otherwise not .

The problem is that it validates the user successfully but when i am trying to specify new UserName which is not exist than it gives me an error like ;

 Request format is unrecognized for URL unexpectedly ending in '/UpdateUserInfo'. 

Following is my code :

 public int UpdateUserInfo(string oldusername, string newusername, string mailid, string password)
    {
        string validateUser = "Select UserName from tbl_UserInfo where UserName='" + newusername + "' ";
        con = new MySqlConnection(conString);
        con.Open();
        MySqlCommand cmd1 = new MySqlCommand(validateUser, con);
        string User = cmd1.ExecuteScalar().ToString();
        con.Close();
        if (User == newusername)
        {
            return 0;
        }
        else 
        {
            string updateUser = "Update tbl_UserInfo SET UserName='" + newusername + "',Password='" + password + "',Email_ID='" + mailid + "' where UserName='" + oldusername + "' ";
            con = new MySqlConnection(conString);
            con.Open();
            MySqlCommand cmd = new MySqlCommand(updateUser, con);
            int success = cmd.ExecuteNonQuery();
            con.Close();

            if (success > 0)
            {
                return success;
            }
            else
                return 0;
        }
    }

NOTE : I want result as ;

         IF my UserName is A and when i update that UserName with same name 
           i.e A than it should not be updated but when i give another name as B 
             than it should be updated by B i.e now UserName A becomes the B

what can be problem ?

Please give solution.

Thanks..

  • 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-04T01:11:52+00:00Added an answer on June 4, 2026 at 1:11 am

    Oh, please use parametrized queries. Ah, and dispose your IDisposable resources. You wil save yourself headaches, SQL injections, improperly formatted data, …

    public int UpdateUserInfo(
        string oldusername, 
        string newusername, 
        string mailid, 
        string password
    )
    {
        using (var con = new MySqlConnection(conString))
        using (var cmd = con.CreateCommand())
        {
            con.Open();
            cmd.CommandText = "SELECT count(UserName) from tbl_UserInfo where UserName = @newusername";
            cmd.Parameters.AddWithValue("@newusername", newusername);
    
            var count = (long)cmd.ExecuteScalar();
            if (count < 1)
            {
                return 0;
            }
        }
    
        using (var con = new MySqlConnection(conString))
        using (var cmd = con.CreateCommand())
        {
            con.Open();
            cmd.CommandText = "UPDATE tbl_UserInfo SET UserName = @newusername, Password = @password, Email_ID = @mailid WHERE UserName = @oldusername";
            cmd.Parameters.AddWithValue("@newusername", newusername);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.AddWithValue("@mailid", mailid);
            cmd.Parameters.AddWithValue("@oldusername", oldusername);
            return cmd.ExecuteNonQuery();
        }
    }
    

    or you could also split those into separate methods:

    public bool UsernameExists(string username)
    {
        using (var con = new MySqlConnection(conString))
        using (var cmd = con.CreateCommand())
        {
            con.Open();
            cmd.CommandText = "SELECT count(UserName) from tbl_UserInfo where UserName = @newusername";
            cmd.Parameters.AddWithValue("@newusername", username);
            return (long)cmd.ExecuteScalar() > 0;
        }
    }
    
    public int Update(string oldusername, string newusername, string mailid, string password)
    {
        using (var con = new MySqlConnection(conString))
        using (var cmd = con.CreateCommand())
        {
            con.Open();
            cmd.CommandText = "UPDATE tbl_UserInfo SET UserName = @newusername, Password = @password, Email_ID = @mailid WHERE UserName = @oldusername";
            cmd.Parameters.AddWithValue("@newusername", newusername);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.AddWithValue("@mailid", mailid);
            cmd.Parameters.AddWithValue("@oldusername", oldusername);
            return cmd.ExecuteNonQuery();
        }
    }
    
    public int UpdateUserInfo(string oldusername, string newusername, string mailid, string password)
    {
        if (!UsernameExists(newusername))
        {
            return Update(oldusername, newusername, mailid, password);
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created Web-Service in asp.net with c# . Now i want to pass
I have created firstly ASP.NET MVC 2 . and write more functionality. After I
I have created blank Asp.Net-MVC 3 web application and want to write my own
I have created a ASP.NET website and deploy it in IIS 7 (in place
I have created a asp.net website and i added tooltip to a button by
Good Morning, I have created an ASP.NET 3.5 webform that allows users to search
I have the following scenario. I have created an ASP.NET web application (framework 3.5)
I have created a web page (ASP.NET) that includes a stylesheet to mimic Dynamics
I have asp.net application. and I have created mobile version of it which is
I have created a basic site using ASP.NET routing according to Mike Ormond's example

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.