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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:36:38+00:00 2026-06-04T06:36:38+00:00

I am having a small issue with SqlServerCe. When using the below sqlString to

  • 0

I am having a small issue with SqlServerCe.
When using the below sqlString to perform a ExecuteNonQuery(); command I get the error below.

string sqlString = "INSERT INTO Images (UID, Name) " +
            "VALUES ((SELECT ID FROM Contributors WHERE ID = @UID), @Name);";

gives this error:

There was an error parsing the query. [ Token line number = 1,Token line offset = 41,Token in error = SELECT ]

Any suggestions?

Method

public static void InsertImage(Contributor contObj, string ImageName)
{
    string sqlString = "INSERT INTO Images (UID, Name) " +
        "VALUES ((SELECT ID FROM [Contributors] WHERE ID = @UID), @Name);";
    using (SqlCeConnection sqlConnection =
        new SqlCeConnection(WebConfigurationManager.ConnectionStrings["DefaultSQL"].ConnectionString))
    {
        SqlCeCommand sqlCommand = new SqlCeCommand(sqlString, sqlConnection);
        sqlCommand.Parameters.AddWithValue("@UID", contObj.ID);
        sqlCommand.Parameters.AddWithValue("@Name", ImageName);
        sqlConnection.Open();
        sqlCommand.ExecuteNonQuery();
        sqlConnection.Close();
    }
}
  • 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-04T06:36:40+00:00Added an answer on June 4, 2026 at 6:36 am

    you will want to use INSERT INTO...SELECT..FROM

    string sqlString = "INSERT INTO Images (UID, Name) " +
                "SELECT ID, @Name FROM Contributors WHERE ID = @UID;";
    

    If you already knew the value for @ID, then you could use the INSERT INTO... VALUES... query

    INSERT INTO Images (UID, Name)
    VALUES (@UID, @Name)
    

    Edit, here is your code with the update query

    public static void InsertImage(Contributor contObj, string ImageName)
    {
        string sqlString = "INSERT INTO Images (UID, Name) " +
            "VALUES (@UID, @Name)";
        using (SqlCeConnection sqlConnection =
            new SqlCeConnection(WebConfigurationManager.ConnectionStrings["DefaultSQL"].ConnectionString))
        {
            SqlCeCommand sqlCommand = new SqlCeCommand(sqlString, sqlConnection);
            sqlCommand.Parameters.AddWithValue("@UID", contObj.ID);
            sqlCommand.Parameters.AddWithValue("@Name", ImageName);
            sqlConnection.Open();
            sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a small issue and wondering if I'm using these correctly. In my SQL
I am having a small issue using the classic WebLogin snippet (Not WebLoginPE) in
I'm using CodeIgniter, and I'm having a small issue with sessions. I've set 'sess_expiration'
I'm on Rails 3 using jQuery. I'm having a small issue with an application
Please i need your help with a small issue i'm having. I'm using the
I'm having an small issue with SQLXML in SQL Server 2008. Here's my testing
I'm having a small issue here: <div id=navbar> <ul id=navtabs class=floatcontainer> <li <?php if
I'm new to LINQ and am having a small issue. I created a DBML
I hope someone here can help me.. I am currently having a small issue
I am having an issue trying to make a small text-fantasy type game involving

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.