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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:31:29+00:00 2026-05-15T23:31:29+00:00

HI i had manullay created textbox’s and then used it for creating a new

  • 0

HI i had manullay created textbox’s and then used it for creating a new user. I am using SQL SERVER 2005 for backend and Visual Server 2008 for front..

I have this LoginAccount table which stores details of the new user created. When i Click the button(in which i have written code to create a new user through SQL insert),

  string strConnection = ConfigurationManager.ConnectionStrings"FHDLConnectionString"].ToString();
        SqlConnection sqlConnection = new SqlConnection(strConnection);
        string username = TextBox1.Text;
        string password = TextBox2.Text;
        string confirmpass = TextBox3.Text;
        string SQLQuery = "Select username From LoginAccount where '" + username + "'";
        string SQLQuery1 = "Insert into LoginAccount values ('" + username + "','" + password + "')";

        SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
        SqlCommand command1 = new SqlCommand(SQLQuery1, sqlConnection);

        sqlConnection.Open();
        string CheckUsername = "";

        if (password.ToString() != confirmpass.ToString())
        {
            Literal1.Text = " Password's does not match ";
        }
        else
        {
            try
            {
                CheckUsername = command.ExecuteScalar().ToString();
            }
            catch (Exception er)
            {
                Literal1.Text = " Username already exists ";
            }

            string insertQuery = "";

            try
            {
                insertQuery = command1.ExecuteScalar().ToString();
                Server.Transfer("Login_Created.aspx");
            }
            catch (Exception er)
            {
                Literal1.Text = " Could not create the user, Please retry with some other option ";
            }
        }
        sqlConnection.Close();

I am getting these exception’s

An expression of non-boolean type specified in a context where a condition is expected, near ‘fhdl’
This error i got at the first catch

and

Object reference not set to an instance of an object.
This for at the last catch.

But the main thing is i am able to insert the username and password into the LoginAccount table!!!!!!! i.e. when i saw the table contents i could see the new user created in that table.
The other thing is This code executed perfectly once before but not now 🙁
Please could anyone tell me where am i going wrong?
I am new to C# with SQl …

  • 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-15T23:31:30+00:00Added an answer on May 15, 2026 at 11:31 pm

    1 – ExecuteScalar() means that there’s a return value. The insert doesn’t have a return value. Use ExecuteNonQuery instead.

    2 – Also, for the insert statement, specify the fields you’re inserting into. Without specifying the fields, it’s trying to insert into the first two columns of the table, which may not be username and password.

    insert into LoginAccount(UserName, Password) values ….

    3 – your select statement is incorrect.

    select from LoginAccount where UserName=’… You’re missing the field name.

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

Sidebar

Related Questions

I had setup a svn server locally, and then tried to setup a username/password
Had a basic question as to the server side behavior while using cookies /
I had a weird issue arise after using CodeMaid to clean up my code.
Had a nice PHP/HTML/JS prototype working on my personal Linode, then tried to throw
Had a Windows Forms app using a WebBrowser control (.NET 4) to load a
Had to deploy some PHP code onto a shared server with only PHP5.2.8. All
Had a basic WinForm question: By default a resx file is created for every
Had a search and only found Differences between SSRS 2005 and 2008 listing the
Had for an photo art project using two images. The first image would be
Had anyone experienced that issue before? What would be a good solution? I'm using

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.