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

  • Home
  • SEARCH
  • 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 7590451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:24:14+00:00 2026-05-30T20:24:14+00:00

I wrote a form based program in C# that uses MS access database to

  • 0

I wrote a form based program in C# that uses MS access database to store its data.

In the MDB file I have a single table named __item__
in the table there are 7 fields of which the first one is called __item_id__ and it is the auto indexer of the table, so when I add new entry it should auto increase each time, so I won’t have 2 entry’s with the same id.

In the program I use the following code (this isn’t the full code, just the relevant one):

using System.Data.OleDb;

private OleDbConnection con; // create connection
private OleDbCommand cmd; // create command   

con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = d:\\library0.1\\DB.mdb");
cmd = new OleDbCommand();
cmd.Connection = con;    

cmd.CommandText = "INSERT INTO Item VALUES (@item_name, @creator_name,@publishing_name,@item_type,@genre,@year_publication);";
con.Open(); // open the connection  
cmd.ExecuteNonQuery(); 
con.Close();

this code will give me an error __ExecuteNonQuery__ claiming I have too few fields.
It wants me to enter the __item_id__ manually, like this:

 cmd.CommandText = "INSERT INTO Item VALUES (@item_id, @item_name, @creator_name,@publishing_name,@item_type,@genre,@year_publication);";

How can I avoid manual input and have the program auto index the item_id for each new entry?

  • 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-30T20:24:15+00:00Added an answer on May 30, 2026 at 8:24 pm

    If you use INSERT INTO without specifying the column list you should provide parameter for all columns.
    To avoid the error change your commandtext to:

    "INSERT INTO Item " + 
    "(item_name, creator_name publishing_name, item_type, genre, year_publication) " +
    "VALUES " + 
    "(@item_name, @creator_name,@publishing_name,@item_type,@genre,@year_publication);";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I initially wrote code to build a form dynamically, based on data from the
We have a program that uses Linq-To-Sql and does a lot of similar queries
I'm trying to write a dropdown form with a submit button that uses Google
I have a program that uploads files to our server when they are dropped
I have a SharePoint web part that I wrote in C# which is used
I wrote an if statement that should write different output depending on the data.
I am writing a program that must communicate with a PHP / web based
I have read several forums that advise against storing videos in a database. I
I have a C# application that uses the SerialPort object to establish a connection
Using Swing in Java I wrote a form containing radio buttons, text fields and

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.