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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:33:56+00:00 2026-05-31T21:33:56+00:00

I have created a class that will manage connection and commands, I named it

  • 0

I have created a class that will manage connection and commands, I named it DbConfiguration and it uses a Singleton pattern(using dbc as an object name).

My problem is this SQL syntax throws an error when I try to run ExecuteNonQuery()

Using this connection string:

"Provider=Microsoft.ACE.OLEDB.12.0;dbms.accdb;Persist Security Info=False"

I executed this first:

dbc.SetCommand("INSERT INTO inventory ([CallNumber], [Title], [ImageLocation]) VALUES (@CALLNUMBER, @TITLE, @IMAGELOC);");
dbc.GetCommand().Parameters.Add("@CALLNUMBER", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("@TITLE", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("@IMAGELOC", System.Data.OleDb.OleDbType.VarChar, 255);

dbc.GetCommand().Parameters["@CALLNUMBER"].Value = txtCallNumber.Text;
dbc.GetCommand().Parameters["@TITLE"].Value = txtTitle.Text;
dbc.GetCommand().Parameters["@IMAGELOC"].Value = (!moveto.Equals("db_storage\\") ? moveto : "db_storage\\no_img.png");

and followed by:

dbc.GetCommand().ExecuteNonQuery();

Next is I executed this code:

dbc.SetCommand("INSERT INTO publishing_info ([ID], [Author], [DateTime], [Publisher], [Pages], [ISBN_NO]) " +
               "VALUES (" +
               "SELECT([ID] FROM inventory " +
               "WHERE inventory.CallNumber=@CALLNUMBER AND inventory.Title=@TITLE AND inventory.ImageLocation=@IMAGELOC), " +
               "@AUTHOR, @DATETIME, @PUBLISHER, @PAGES, @ISBN);");

and also followed by:

dbc.GetCommand().ExecuteNonQuery();

Here are the parameters that I have used for your reference:

dbc.GetCommand().Parameters.Add("@AUTHOR", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("@DATETIME", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("@PUBLISHER", System.Data.OleDb.OleDbType.VarChar, 255);
dbc.GetCommand().Parameters.Add("@PAGES", System.Data.OleDb.OleDbType.UnsignedInt, 4);
dbc.GetCommand().Parameters.Add("@ISBN", System.Data.OleDb.OleDbType.VarChar, 255);

dbc.GetCommand().Parameters["@AUTHOR"].Value = txtAuthor.Text;
dbc.GetCommand().Parameters["@DATETIME"].Value = txtYear.Text;
dbc.GetCommand().Parameters["@PUBLISHER"].Value = txtPublisher.Text;
dbc.GetCommand().Parameters["@PAGES"].Value = uint.Parse(txtPages.Text);
dbc.GetCommand().Parameters["@ISBN"].Value = txtISBN.Text;

Here is the screenshot of my stack trace(I can’t attach it because I only have 1 rep points)
http://i44.tinypic.com/2w49t84.png

What should I do to make the syntax work?
And also do I need to close the connection first before executing another query?

Update 1

I used DMax(\"[ID]\", \"inventory\") to retrieve the last ID but it returns all the fields of inventory and writes it all on the fields that it can be written to, in my C# code but if I write the query on MS Access 2010 it doesn’t do what it does on a C# code. What seems to be the problem?

Update 2

Problem solved with dbc.GetCommand().Parameters.Clear()

  • 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-31T21:33:57+00:00Added an answer on May 31, 2026 at 9:33 pm

    You do not need to close the connection, but you do need to insert a left parenthesis in your sub-select:

    dbc.SetCommand("INSERT INTO publishing_info ([ID], [Author], [DateTime], [Publisher], [Pages], [ISBN_NO]) " +
               "VALUES (" +
               "(SELECT([ID] FROM inventory " +
               "WHERE inventory.CallNumber=@CALLNUMBER AND inventory.Title=@TITLE AND inventory.ImageLocation=@IMAGELOC), " +
               "@AUTHOR, @DATETIME, @PUBLISHER, @PAGES, @ISBN);");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a button CSS class that uses background images with different positions
I have created a service class for my network connection so that my app
I have created a non-form c# program that uses the NotifyIcon class. The text
I have created a class that I've been using as the storage for all
I have written an apex class that will create a PDF quote and attach
Currently I have created a ABCFactory class that has a single method creating ABC
I have created a custom collection class that I am trying to bind to
I have a binary tree class that is created with a root node and
I have created a gem that adds a new method to the class ActiveRecord::Base.
I have created a subclass of UITableViewController that is used as the custom class

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.