I’m very new to C# and trying to insert multiple values to an access database, one of which will increment by 1. I cannot use auto-number in access because the entries start at 99001 and I will need the ability to edit/skip numbers easily. Ive been trying different posts all day that were similar to this, but all of them cause errors or just don’t work. My code is currently as follows.
AccessDataSource1.InsertCommand = "INSERT INTO [1U] ([serial], [model], [motherboard], [mobogroup], [bios]) SELECT ((SELECT MAX([serial])+1 FROM [1U]), ?, ?, ?, ?)";
AccessDataSource1.InsertParameters["serial"].DefaultValue = "1";
AccessDataSource1.InsertParameters["model"].DefaultValue = "D";
AccessDataSource1.InsertParameters["motherboard"].DefaultValue = "D";
AccessDataSource1.InsertParameters["mobogroup"].DefaultValue = "D";
AccessDataSource1.InsertParameters["bios"].DefaultValue = "D";
with the button calling this as
<asp:Button ID="InsertButton" runat="server" OnClick="update_click" CausesValidation="True" CommandName="Insert" Text="Insert" />
but this gives me an error saying “Number of query values and destination fields are not the same.” any ideas on how to fix this or alternate ways to achieve the result I am looking for?
You can trick MS Access into using a seeded autonumber, see Create an AutoNumber field that starts with a number greater than 1 for an example on how to do this.